diff --git a/CMakeLists.txt b/CMakeLists.txt index 2145923..fc18e3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ add_subdirectory(WoW/Source/Net) add_subdirectory(WoW/Source/Object) add_subdirectory(WoW/Source/ObjectAlloc) add_subdirectory(WoW/Source/ObjectMgrClient) +add_subdirectory(WoW/Source/SoundInterface) add_subdirectory(WoW/Source/UIUtil) add_subdirectory(WoW/Source/Ui) add_subdirectory(WoW/Source/WorldClient) diff --git a/Engine/Source/BlizzardCore/SFile2-Core.h b/Engine/Source/BlizzardCore/SFile2-Core.h index 2679e19..ca815a8 100644 --- a/Engine/Source/BlizzardCore/SFile2-Core.h +++ b/Engine/Source/BlizzardCore/SFile2-Core.h @@ -71,6 +71,7 @@ class SFile { static int32_t STORMAPI FileExists(const char* name); static int32_t STORMAPI FileExistsEx(const char* name, uint32_t flags); static int32_t STORMAPI FileGetIsLocalAmount(const char* name, int64_t& local, int64_t& total); + static int32_t STORMAPI FileIsLocal(const char* name, int32_t flags); static int32_t STORMAPI FileIsLocal(SFileImpl* file, int32_t flags); static int32_t STORMAPI GetActualFileName(SFileImpl* file, char* buffer, uint32_t size); static int32_t STORMAPI GetBasePath(char* path, uint32_t size); @@ -80,6 +81,7 @@ class SFile { static int32_t IsStreamingMode(); static int32_t IsTrial(); static int32_t STORMAPI LoadFile(const char* name, void** data, uint32_t* size, uint32_t extra, SOVERLAPPED* overlapped); + static int32_t STORMAPI MakeFileLocal(const char* name, int32_t priority, bool wait); static int32_t STORMAPI MakeFileLocal(SFileImpl* file, int32_t priority, bool wait); static int32_t STORMAPI OpenArchive(const char* path, int32_t priority, uint32_t flags, SArchive** archive); static int32_t STORMAPI OpenEx(SArchive* archive, const char* name, uint32_t flags, SFileImpl** result); diff --git a/WoW/Source/CMakeLists.txt b/WoW/Source/CMakeLists.txt index 6b017dd..940402e 100644 --- a/WoW/Source/CMakeLists.txt +++ b/WoW/Source/CMakeLists.txt @@ -59,6 +59,7 @@ target_link_libraries(Wow Object ObjectAlloc ObjectMgrClient + SoundInterface UIUtil Ui WorldClient diff --git a/WoW/Source/DB/DBClient/DBClient.h b/WoW/Source/DB/DBClient/DBClient.h index a09f9fc..31031ee 100644 --- a/WoW/Source/DB/DBClient/DBClient.h +++ b/WoW/Source/DB/DBClient/DBClient.h @@ -484,6 +484,8 @@ extern WowClientDB_RLE g_lightFloatBandDB; extern WowClientDB g_lightParamsDB; extern WowClientDB g_lightDB; +int32_t ClientDBGetNumWeaponSubClasses(); +int32_t ClientDBGetUnarmedWeapon(); void ClientDBInitialize(); void GameTablesInitialize(); void InitLights(int32_t mode); diff --git a/WoW/Source/Game/GameClient/ComSatClient.h b/WoW/Source/Game/GameClient/ComSatClient.h index e7274c8..deed4fa 100644 --- a/WoW/Source/Game/GameClient/ComSatClient.h +++ b/WoW/Source/Game/GameClient/ComSatClient.h @@ -1,4 +1,20 @@ #ifndef WOW_SOURCE_GAME_GAMECLIENT_COMSATCLIENT_H #define WOW_SOURCE_GAME_GAMECLIENT_COMSATCLIENT_H +#include +#include + +struct CVar; + +void ComSatClient_SetCaptureDevice(int32_t index); +void ComSatClient_SetOutputDevice(int32_t index); +bool EnableMicrophoneHandler(CVar* var, const char* oldValue, const char* value, void* arg); +bool EnableVoiceChatHandler(CVar* var, const char* oldValue, const char* value, void* arg); +bool InboundChatVolumeHandler(CVar* var, const char* oldValue, const char* value, void* arg); +bool OutboundChatVolumeHandler(CVar* var, const char* oldValue, const char* value, void* arg); +bool PushToTalkButtonHandler(CVar* var, const char* oldValue, const char* value, void* arg); +bool SelfMuteHandler(CVar* var, const char* oldValue, const char* value, void* arg); +bool VoiceActivationSensitivityHandler(CVar* var, const char* oldValue, const char* value, void* arg); +bool VoiceChatModeHandler(CVar* var, const char* oldValue, const char* value, void* arg); + #endif diff --git a/WoW/Source/Game/GameTime.h b/WoW/Source/Game/GameTime.h index 59270b0..89ee073 100644 --- a/WoW/Source/Game/GameTime.h +++ b/WoW/Source/Game/GameTime.h @@ -20,6 +20,11 @@ class CGameTime : public WowTime { /* 0044 */ float m_baseMinuteOfDay; /* 0048 */ float unk_0048; /* 004C */ float unk_004C; + + float GameTimeGetDayProgression(); + bool IsDaytime(); }; +extern CGameTime g_clientGameTime; + #endif diff --git a/WoW/Source/Object/ObjectClient/Item_C.h b/WoW/Source/Object/ObjectClient/Item_C.h index d1ff054..092bf84 100644 --- a/WoW/Source/Object/ObjectClient/Item_C.h +++ b/WoW/Source/Object/ObjectClient/Item_C.h @@ -8,6 +8,8 @@ class CGItem_C : public CGObject_C, public CGItem { public: + static int32_t IsMetal(int32_t materialId); + /* 00D8 */ void* unk_00D8; /* 00DC */ uint32_t unk_00DC [192]; /* 03DC */ uint8_t unk_03DC [4]; diff --git a/WoW/Source/Object/ObjectClient/Unit_C.h b/WoW/Source/Object/ObjectClient/Unit_C.h index 47a179e..067c03b 100644 --- a/WoW/Source/Object/ObjectClient/Unit_C.h +++ b/WoW/Source/Object/ObjectClient/Unit_C.h @@ -197,6 +197,8 @@ class CGUnit_C : public CGObject_C, public CGUnit { /* 0F68 */ uint32_t m_objectclass1 [38]; /* 1000 */ uint32_t unk_1000; /* 1004 */ uint8_t unk_1004 [4]; + + bool IsActivePlayer(); }; class CAnimKitManager { diff --git a/WoW/Source/ObjectMgrClient/ObjectMgrClient.h b/WoW/Source/ObjectMgrClient/ObjectMgrClient.h index de187e4..be0bca8 100644 --- a/WoW/Source/ObjectMgrClient/ObjectMgrClient.h +++ b/WoW/Source/ObjectMgrClient/ObjectMgrClient.h @@ -45,4 +45,6 @@ class ObjectMgr { /* 00D4 */ CMovementGlobals* m_movementGlobal; }; +uint64_t ClntObjMgrGetActivePlayer(); + #endif diff --git a/WoW/Source/SoundInterface/CMakeLists.txt b/WoW/Source/SoundInterface/CMakeLists.txt new file mode 100644 index 0000000..c555e69 --- /dev/null +++ b/WoW/Source/SoundInterface/CMakeLists.txt @@ -0,0 +1,10 @@ +file(GLOB_RECURSE PRIVATE_SOURCES CONFIGURE_DEPENDS "*.cpp") + +add_library(SoundInterface STATIC + ${PRIVATE_SOURCES} +) + +target_include_directories(SoundInterface + PUBLIC + ${CMAKE_SOURCE_DIR} +) diff --git a/WoW/Source/SoundInterface/SoundInterface2.cpp b/WoW/Source/SoundInterface/SoundInterface2.cpp new file mode 100644 index 0000000..3dc4167 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2.cpp @@ -0,0 +1,1351 @@ +#include +#include +#include +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "Engine/Source/Base/CmdLine.h" +#include "Engine/Source/BlizzardCore/SFile2-Core.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/Event/Event.h" +#include "Engine/Source/Os/TimeManager.h" +#include "Engine/Source/Storm/H/storm.h" +#include "Engine/Source/Tempest/CRandom.h" +#include "Engine/Source/Tempest/CRange.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Game/GameClient/ComSatClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.h" +#include "WoW/Source/SoundInterface/SoundInterface2Internal.h" +#include "WoW/Source/SoundInterface/SoundInterface2ZoneSounds.h" +#include "WoW/Source/Ui/ChatFrame.h" +#include "WoW/Source/Ui/GameUI.h" + +// STATIC: 0x009F2010 +const char SI2::s_channelGroupNames[18][32] = { + "SFX", + "MUSIC", + "AMBIENCE", + "CINEMATIC", + "SCRIPTSOUND", + "SCRIPTMUSIC", + "RACIALCINEMATIC", + "SFX", + "SFX", + "SFX", + "SFX", + "SFX", + "SFX", + "SFX", + "SFX", + "SFX", + "SFX", + "SFX", +}; + +// STATIC: 0x009F2268 +const int32_t SI2::s_channelGroupMaxSounds[18] = { + 0x7FFFFFFF, + 0x7FFFFFFF, + 0x7FFFFFFF, + 0x7FFFFFFF, + 0x7FFFFFFF, + 0x7FFFFFFF, + 1, + 1, + 2, + 1, + 2, + 2, + 1, + 6, + 4, + 1, + 2, + 4, +}; + +// STATIC: 0x00B4A340 +int32_t SI2::s_channelGroupNumSounds[18]; + +// STATIC: 0x00B4A390 +TSGrowableArray SI2::s_suppressors; + +// STATIC: 0x00B4A3A0 +static const char* s_savedVoiceSession; + +// STATIC: 0x00AC3860 +static int32_t s_savedVoiceSessionType = 4; + +// STATIC: 0x00B4A3E4 +static float s_chaosRestartTimer; + +// STATIC: 0x00B4A3E8 +static float s_chaosTimer; + +// STATIC: 0x00B4A3EC +static int32_t s_chaosElapsedMs; + +// STATIC: 0x00B4AA94 +int32_t SI2::sm_bPlayerInside; + +// STATIC: 0x00B4AA98 +int32_t SI2::sm_bCameraIsUnderwater; + +// STATIC: 0x00B4AA9C +int32_t SI2::sm_bUnderwaterChanged; + +// STATIC: 0x00B4AAA0 +uint32_t SI2::sm_nextZoneMusicTime; + +// STATIC: 0x00B4AAA4 +int32_t SI2::sm_bLuaMusicPlaying; + +// VERIFY: 8cb9a901 manual +// OFFSET: 0x004C5B60 +static int32_t GetDownloadPriority(int32_t group) { + if (group <= 0 || group > 2) { + return 5; + } + + return 6; +} + +// VERIFY: 964e6036 auto +// OFFSET: 0x004C5990 +void SE2SoundKitProperties::ResetToDefaults() { + this->m_volume = -1.0f; + this->m_volumeScale = 1.0f; + this->m_fileIndex = -1; + this->m_priority = -1; + this->m_fadeInTime = 0.0f; + this->m_fadeOutTime = 0.0f; + this->m_group = 0; + this->m_selectMode = 2; + this->m_maxDistance = -1.0f; + this->m_loopMode = 0; + this->m_muteFadeSpeed = 0.5f; + this->m_suppressorMode = 0; + this->m_decodeBufferSize = 0; + this->m_maxAudibleBehavior = 1; + this->m_coneInsideAngle = 360.0f; + this->m_reverb = 1; + this->m_coneOutsideAngle = 360.0f; + this->m_streaming = false; + this->m_noRandomStart = 0; + this->m_blockMusicFiles = 0; + this->m_software = 0; + this->m_coneOutsideVolume = 1.0f; + this->m_coneOrientation = nullptr; + this->m_useDspChain = 0; + this->m_forceLoop = 0; + this->m_checkStreaming = SFile::IsStreamingMode() != 0; +} + +// VERIFY: 24efb61f manual +// OFFSET: 0x004C5A20 +float SI2::GetChannelGroupVolume(int32_t group) { + return SE2::GetChannelGroupVolume(SI2::s_channelGroupNames[group]); +} + +// VERIFY: e2c427b3 auto +// OFFSET: 0x004C5A40 +void SI2::SetChannelGroupVolume(int32_t group, float volume) { + SE2::SetChannelGroupVolume(SI2::s_channelGroupNames[group], volume); +} + +// VERIFY: 44756337 auto +// OFFSET: 0x004C5A60 +int32_t SI2::GetNumInputDrivers(int32_t chatSystem) { + return SE2::GetNumInputDrivers(chatSystem); +} + +// VERIFY: fc888c05 auto +// OFFSET: 0x004C5A70 +int32_t SI2::GetNumInputDrivers_Cached(int32_t chatSystem) { + return SE2::GetNumInputDrivers_Cached(chatSystem); +} + +// VERIFY: 7129b2b8 auto +// OFFSET: 0x004C5A80 +bool SI2::GetInputDriverName(int32_t index, char* name, int32_t nameLength, int32_t chatSystem) { + return SE2::GetInputDriverName(index, name, nameLength, chatSystem); +} + +// VERIFY: 13e146d1 auto +// OFFSET: 0x004C5A90 +bool SI2::GetInputDriverName_Cached(int32_t index, char* name, int32_t nameLength, int32_t chatSystem) { + return SE2::GetInputDriverName_Cached(index, name, nameLength, chatSystem); +} + +// VERIFY: 13fd08cb auto +// OFFSET: 0x004C5AA0 +int32_t SI2::GetNumOutputDrivers(int32_t chatSystem) { + return SE2::GetNumOutputDrivers(chatSystem); +} + +// VERIFY: 7fd5990c auto +// OFFSET: 0x004C5AB0 +int32_t SI2::GetNumOutputDrivers_Cached(int32_t chatSystem) { + return SE2::GetNumOutputDrivers_Cached(chatSystem); +} + +// VERIFY: ab40eaf2 manual +// OFFSET: 0x004C5AC0 +bool SI2::GetOutputDriverName(int32_t index, char* name, int32_t nameLength, int32_t chatSystem) { + if (index < 0) { + index = 0; + } + + return SE2::GetOutputDriverName(index, name, nameLength, chatSystem); +} + +// VERIFY: 59635ee4 manual +// OFFSET: 0x004C5AF0 +bool SI2::GetOutputDriverName_Cached(int32_t index, char* name, int32_t nameLength, int32_t chatSystem) { + if (index < 0) { + index = 0; + } + + return SE2::GetOutputDriverName_Cached(index, name, nameLength, chatSystem); +} + +// VERIFY: 8c87872b auto +// OFFSET: 0x004C5B20 +int32_t SI2::SetListenerAttributes(const C3Vector* position, const C3Vector* forward, const C3Vector* up, const C3Vector* velocity) { + SE2::SetListenerAttributes(position, forward, up, velocity); + return 0; +} + +// VERIFY: ae8eb23a manual +// OFFSET: 0x004C5B40 +int32_t SI2::GetListenerPosition(C3Vector* position) { + if (!position) { + return 1; + } + + SE2::GetListenerPosition(position); + return 0; +} + +// VERIFY: 75af4810 manual +// OFFSET: 0x004C5B80 +void SI2::StopAllSounds() { + SE2::StopAllSounds(); +} + +// VERIFY: 696f4de8 auto +// OFFSET: 0x004C5B90 +int32_t SI2::Set3DPosition(SE2SoundKitObject* object, const C3Vector* position) { + if (object->m_advancedId) { + SI2::SetAdvancedSoundPosition(object->m_advancedId, position); + } + + object->m_sound.Set3DPosition(*position); + return 0; +} + +// VERIFY: 8ab4a07a auto +// OFFSET: 0x004C5BC0 +int32_t SI2::SetVolume(SE2SoundKitObject* object, float volume) { + object->m_sound.SetVolume(volume); + return 0; +} + +// VERIFY: ff3bc1d9 auto +// OFFSET: 0x004C5BE0 +bool SI2::IsPlaying(SE2SoundKitObject* object) { + return object->m_sound.IsPlaying(); +} + +// VERIFY: 2a2ff92d auto +// OFFSET: 0x004C5BF0 +uint32_t SI2::IsSoundKitLooping(int32_t soundKitId) { + VSOUNDKITDEF* def = SI2::GetSoundKitDef(soundKitId); + + if (!def) { + return 0; + } + + return def->m_flags & 0x200; +} + +// VERIFY: dd9e9845 manual +// OFFSET: 0x004C5C10 +int32_t SI2::GetSoundKitUsage(int32_t soundKitId) { + VSOUNDKITDEF* def = SI2::GetSoundKitDef(soundKitId); + + if (def && def->m_advanced) { + return def->m_advanced->m_usage; + } + + return 2; +} + +// VERIFY: 9ff69350 manual +// OFFSET: 0x004C5C40 +bool SI2::IsLooping(SE2SoundKitObject* object) { + return object->m_sound.IsLooping(); +} + +// VERIFY: 3dddcdd1 auto +// OFFSET: 0x004C5C60 +int32_t SI2::GetNumSoundsInSoundKit(int32_t soundKitId) { + VSOUNDKITDEF* def = SI2::GetSoundKitDef(soundKitId); + + if (!def) { + return 0; + } + + return def->m_numFiles; +} + +// VERIFY: 0259b8b2 auto +// OFFSET: 0x004C5C80 +int32_t SI2::AttachToObject(SE2SoundKitObject* object, uint64_t guid) { + if (!object->m_sound.Is3D()) { + return 12; + } + + object->m_sound.AttachToObject(guid); + return 0; +} + +// VERIFY: f1864be0 auto +// OFFSET: 0x004C5CC0 +void SI2::StopAllSounds(float fadeOutTime) { + SE2::StopAllSounds(SI2::s_channelGroupNames[0], fadeOutTime); +} + +// VERIFY: 218e92b2 auto +// OFFSET: 0x004C5CE0 +int32_t SI2ZoneSoundPair::GetCurrentType() { + return this->m_sounds[this->m_current].m_type; +} + +// VERIFY: 702244e3 manual +// OFFSET: 0x004C5D00 +bool SI2ZoneSoundPair::IsPlaying() { + return this->m_sounds[this->m_current].m_object.m_sound.IsPlaying(); +} + +// VERIFY: 1c86efa7 auto +// OFFSET: 0x004C5D20 +void SI2ZoneSoundPair::SetFinishedCallback(void (*callback)(SESound*, void*), void* param) { + this->m_sounds[this->m_current].m_object.m_sound.SetFinishedCallback2(callback, param); +} + +// VERIFY: 0f619923 auto +// OFFSET: 0x004C5DC0 +int32_t SI2::OnFocusChanged(const void* data, void* param) { + static CVar* s_enableSoundWhenGameIsInBG = CVar::Lookup("Sound_EnableSoundWhenGameIsInBG"); + + CVar* enableVoiceChat = CVar::Lookup("EnableVoiceChat"); + const int32_t* focus = static_cast(data); + + if (!focus) { + return 1; + } + + if (*focus) { + SE2::MuteAllSound(false); + SE2::MuteChannelGroup("CINEMATIC", false); + + if (CGGameUI::m_initialized && enableVoiceChat && enableVoiceChat->m_intValue && s_savedVoiceSession) { + CGChat::SetActiveVoiceSession(s_savedVoiceSession, s_savedVoiceSessionType, -1); + s_savedVoiceSession = nullptr; + s_savedVoiceSessionType = 4; + } + } else if (s_enableSoundWhenGameIsInBG->m_intValue) { + SE2::MuteAllSound(false); + SE2::MuteChannelGroup("CINEMATIC", false); + } else { + SE2::MuteAllSound(true); + SE2::MuteChannelGroup("CINEMATIC", true); + + if (CGGameUI::m_initialized && !s_savedVoiceSession) { + s_savedVoiceSession = CGChat::GetChannelStringForDisplay(CGChat::GetActiveVoiceSession(), &s_savedVoiceSessionType); + CGChat::SetActiveVoiceSession(nullptr, 4, -1); + } + } + + return 1; +} + +// VERIFY: e5b8f14f manual +// OFFSET: 0x004C5F00 +static C3Vector RandomListenerOffset() { + C3Vector listener; + listener.x = 0.0f; + listener.y = 0.0f; + listener.z = 0.0f; + + float scale = CRandom::sfloat_(g_rndSeed); + C3Vector direction = CRandom::C3Vector_(g_rndSeed); + float x = direction.x * scale * 50.0f; + float y = direction.y * scale * 50.0f; + float z = direction.z * scale * 50.0f; + + SE2::GetListenerPosition(&listener); + + return C3Vector(x + listener.x, y + listener.y, z + listener.z); +} + +// VERIFY: ecf8304e manual +// OFFSET: 0x004C5FB0 +void SI2::ValidateVoiceChatOutputDriver() { + char name[256]; + char current[256]; + + int32_t count = SE2::GetNumOutputDrivers_Cached(1); + int32_t missing = 1; + + for (int32_t i = 0; i < count; i++) { + SE2::GetOutputDriverName_Cached(i, current, sizeof(current), 1); + + if (!strcmp(SE2::GetCurrentChatOutputDeviceName(), current)) { + missing = 0; + break; + } + } + + static CVar* s_outputDriverIndex = CVar::Lookup("Sound_VoiceChatOutputDriverIndex"); + + if (missing || (!s_outputDriverIndex->m_intValue && (SE2::GetOutputDriverName_Cached(1, name, sizeof(name), 1), strcmp(SE2::GetCurrentChatOutputDeviceName(), name)))) { + s_outputDriverIndex->Set("0", true, false, false, true); + ComSatClient_SetOutputDevice(0); + } +} + +// VERIFY: ded1a63e manual +// OFFSET: 0x004C60F0 +void SI2::ValidateVoiceChatInputDriver() { + char name[256]; + char current[256]; + + int32_t count = SE2::GetNumInputDrivers_Cached(1); + int32_t missing = 1; + + for (int32_t i = 0; i < count; i++) { + SE2::GetInputDriverName_Cached(i, current, sizeof(current), 1); + + if (!strcmp(SE2::GetCurrentChatInputDeviceName(), current)) { + missing = 0; + break; + } + } + + static CVar* s_inputDriverIndex = CVar::Lookup("Sound_VoiceChatInputDriverIndex"); + + if (missing || (!s_inputDriverIndex->m_intValue && (SE2::GetInputDriverName_Cached(1, name, sizeof(name), 1), strcmp(SE2::GetCurrentChatInputDeviceName(), name)))) { + s_inputDriverIndex->Set("0", true, false, false, true); + ComSatClient_SetCaptureDevice(0); + } +} + +// VERIFY: f1a4c4cd manual +// OFFSET: 0x004C6230 +int32_t SI2::ShutDown(int32_t restart) { + EventUnregister(EVENT_ID_FOCUS, SI2::OnFocusChanged); + EventUnregister(EVENT_ID_POLL, SI2::UpdateAdvancedSounds); + + if (!restart) { + SI2::ClearSuppressorSounds(); + } + + SE2::StopAllSounds(); + + if (!restart) { + SI2::FreeWorldStateZoneSoundOverrides(); + SI2::FreeZoneSoundOverrides(); + SI2::FreeFootstepSounds(); + SI2::FreeEmoteSounds(); + } + + SI2::DSP_ShutDown(); + SE2::UnregisterHeartBeat(); + SI2::ReleaseSoundGroups(); + + if (!restart) { + SI2::FreeSoundKitDefs(); + } + + SE2::ShutDown(restart); + + if (!restart) { + SI2::DestroyVSoundLookup(); + } + + return 0; +} + +// VERIFY: a240cc52 auto +// OFFSET: 0x004C62B0 +void SI2::SoundFinished(SESound* sound, void* param) { + SI2SoundUserData* userData = static_cast(sound->GetUserData()); + + if (!userData) { + return; + } + + SI2::s_channelGroupNumSounds[userData->m_group]--; + + if (userData->m_advancedId && userData->m_def && userData->m_def->m_advanced && userData->m_def->m_advanced->m_usage == 2) { + SI2::MarkAdvancedSoundStopped(userData->m_advancedId); + } + + VSOUNDKITDEF* def = userData->m_def; + + if (def && (def->m_flags & 0x20)) { + int32_t id = def->m_id; + + for (uint32_t i = 0; i < SI2::s_suppressors.Count(); i++) { + if (SI2::s_suppressors[i] == id) { + SI2::s_suppressors[i] = 0; + return; + } + } + } +} + +// VERIFY: 551d00f9 auto +// OFFSET: 0x004C6330 +int32_t SI2::ResetSoundKitVariants(const char* name) { + int32_t soundKitId = SI2::LookupSoundKitId(name); + + if (!soundKitId) { + return 7; + } + + VSOUNDKITDEF* def = SI2::GetSoundKitDef(soundKitId); + + if (!def) { + return 5; + } + + if (!def->m_numFiles) { + return 6; + } + + def->ResetWeights(); + def->m_lastIndex = -1; + return 0; +} + +// VERIFY: 2c0f24c2 auto +// OFFSET: 0x004C6390 +int32_t SI2::StopSound(SE2SoundKitObject* object, int32_t immediate, float fadeOutTime, int32_t stopAdvanced) { + SI2SoundUserData* userData = static_cast(object->m_sound.GetUserData()); + + if (userData) { + VSOUNDKITDEF* def = userData->m_def; + + if (def && (def->m_flags & 0x20)) { + int32_t id = def->m_id; + + for (uint32_t i = 0; i < SI2::s_suppressors.Count(); i++) { + if (SI2::s_suppressors[i] == id) { + SI2::s_suppressors[i] = 0; + break; + } + } + } + } + + object->m_sound.Stop(immediate, fadeOutTime); + + if (stopAdvanced) { + SI2::StopAdvancedSound(object->m_advancedId); + } + + return 0; +} + +// VERIFY: 8b75cf26 manual +// OFFSET: 0x004C6410 +int32_t SI2ZoneSoundPair::GetPlayingSoundKitId() { + if (this->m_sounds[this->m_current].m_object.m_sound.IsPlaying()) { + return this->m_sounds[this->m_current].m_soundKitId; + } + + return 0; +} + +// VERIFY: 71a7805b manual +// OFFSET: 0x004C6450 +void SI2ZoneSoundPair::Stop(int32_t immediate) { + SI2::StopSound(&this->m_sounds[this->m_current].m_object, immediate, -1.0f, 1); + this->m_sounds[this->m_current].m_type = 13; + this->m_sounds[this->m_current].m_soundKitId = 0; + + SI2::StopSound(&this->m_sounds[this->m_next].m_object, immediate, -1.0f, 1); + this->m_sounds[this->m_next].m_type = 13; + this->m_sounds[this->m_next].m_soundKitId = 0; +} + +// VERIFY: 42b96170 auto +// OFFSET: 0x004C6500 +SI2SoundUserData::SI2SoundUserData() { + this->m_name = nullptr; + this->m_soundKitId = 0; + this->m_def = nullptr; + this->m_group = 0; + this->unk_0014 = 0; + this->m_advancedId = 0; +} + +// VERIFY: d9247093 manual +// OFFSET: 0x004C6520 +SI2SoundUserData::~SI2SoundUserData() { + this->m_name = nullptr; + this->m_soundKitId = 0; + this->m_def = nullptr; + this->m_group = 0; + this->unk_0014 = 0; + this->m_advancedId = 0; +} + +// VERIFY: 43b346c5 auto +// OFFSET: 0x00532950 +void SI2SoundUserData::Release() { + delete this; +} + +// VERIFY: a4a74c7f manual +// OFFSET: 0x004C6560 +void SI2::ValidateOutputDriver() { + char name[256]; + char current[256]; + + int32_t count = SE2::GetNumOutputDrivers_Cached(0); + int32_t missing = 1; + + for (int32_t i = 0; i < count; i++) { + SE2::GetOutputDriverName_Cached(i, current, sizeof(current), 0); + + if (!strcmp(SE2::GetCurrentGameOutputDeviceName(), current)) { + missing = 0; + break; + } + } + + static CVar* s_outputDriverIndex = CVar::Lookup("Sound_OutputDriverIndex"); + + if (missing || (!s_outputDriverIndex->m_intValue && (SE2::GetOutputDriverName_Cached(1, name, sizeof(name), 0), strcmp(SE2::GetCurrentGameOutputDeviceName(), name)))) { + s_outputDriverIndex->Set("0", true, false, false, true); + int32_t restart = count != 0; + SI2::ShutDown(restart); + SI2::Init(restart); + } +} + +// VERIFY: bc4053ef auto +// OFFSET: 0x004C6700 +void SI2::RegisterDeviceChangeHandler() { + EventRegister(EVENT_ID_POLL, SI2::HandleSoundDeviceChange); +} + +// VERIFY: 5c43095a manual +// OFFSET: 0x004C6A40 +int32_t SI2::PlaySoundKit(int32_t soundKitId, const C3Vector* position, SE2SoundKitObject* object, SE2SoundKitProperties* properties, uint32_t advancedId, uint32_t* soundId, int32_t checkDistance, int32_t keepPlaying) { + if (soundKitId <= 0) { + return 5; + } + + VSOUNDKITDEF* def = SI2::GetSoundKitDef(soundKitId); + + if (!def) { + return 5; + } + + if (!def->m_numFiles) { + return 6; + } + + if (!SE2::IsInitialized()) { + return 17; + } + + static CVar* s_enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + + if (!s_enableAllSound || !s_enableAllSound->m_intValue || CGGameUI::m_inMovie) { + return 17; + } + + SE2SoundKitProperties defaults; + defaults.ResetToDefaults(); + + if (!properties) { + properties = &defaults; + } + + if (SI2::s_channelGroupNumSounds[properties->m_group] >= SI2::s_channelGroupMaxSounds[properties->m_group]) { + return 14; + } + + if (!strcmp(SI2::s_channelGroupNames[properties->m_group], "SFX")) { + static CVar* s_enableSFX = CVar::Lookup("Sound_EnableSFX"); + + if (!s_enableSFX || !s_enableSFX->m_intValue) { + return 9; + } + } + + if (!strcmp(SI2::s_channelGroupNames[properties->m_group], "MUSIC") || !strcmp(SI2::s_channelGroupNames[properties->m_group], "SCRIPTMUSIC")) { + static CVar* s_enableMusic = CVar::Lookup("Sound_EnableMusic"); + + if (!s_enableMusic || !s_enableMusic->m_intValue) { + return 10; + } + } + + if (properties->m_group == 2) { + static CVar* s_enableAmbience = CVar::Lookup("Sound_EnableAmbience"); + + if (!s_enableAmbience || !s_enableAmbience->m_intValue) { + return 11; + } + } + + if (properties->m_group >= 18) { + return 8; + } + + if (CGChat::IsPaused() && !position) { + return 9; + } + + if (properties->m_suppressorMode == 2) { + def->m_flags |= 0x20; + } + + if (properties->m_suppressorMode == 1) { + def->m_flags &= ~0x20u; + } + + if (def->m_flags & 0x20) { + for (uint32_t i = 0; i < SI2::s_suppressors.Count(); i++) { + if (SI2::s_suppressors[i] == static_cast(soundKitId)) { + return 15; + } + } + } + + SESound localSound; + SESound* sound; + + if (object) { + sound = &object->m_sound; + + if (!keepPlaying) { + SI2::StopSound(object, 1, -1.0f, 1); + } + } else { + sound = &localSound; + properties->m_loopMode = 2; + } + + const char* file = def->SelectFile(properties->m_selectMode, nullptr, properties->m_fileIndex, GetDownloadPriority(properties->m_group)); + + if (!file) { + return 16; + } + + if (properties->m_checkStreaming) { + int32_t local = SFile::FileIsLocal(file, GetDownloadPriority(properties->m_group)); + + if (local != 1) { + if (properties->m_group == 6) { + if (!SFile::MakeFileLocal(file, 2, true)) { + return 16; + } + } else if (local == 0 || local == 2) { + if (local == 0) { + SFile::MakeFileLocal(file, GetDownloadPriority(properties->m_group), false); + } + + def->m_downloadPending = 1; + return 20; + } + } + } + + def->m_downloadPending = 0; + + if (properties->m_blockMusicFiles && (SStrStrI(file, "music") || SStrStrI(file, "ambience") || SStrStrI(file, "cinematic"))) { + return 16; + } + + int32_t looping = 0; + + if (properties->m_loopMode == 0) { + looping = def->m_flags & 0x200; + } else if (properties->m_loopMode == 1) { + looping = 1; + } + + if (properties->m_forceLoop) { + looping = 1; + properties->m_maxAudibleBehavior = 0; + properties->m_streaming = true; + properties->m_software = 1; + } + + if (looping && !object) { + DebugLog("XXXX\nXXXX ERROR!! Sound Kit ID %d is a looping sound but there is no user handle! This sound will play forever!! \nXXXX\n", soundKitId); + } + + SE2::SetSoundGroupMaxAudibleBehavior(def->m_loadSoundGroup, 1, 0.0f); + SE2::SetSoundGroupMaxAudibleBehavior(def->m_soundGroup, properties->m_maxAudibleBehavior, properties->m_muteFadeSpeed); + + if (def->m_advanced && !advancedId) { + SI2::AddAdvancedSound(def->m_advanced, soundKitId, position, properties->m_coneOrientation, object, 0, 0, checkDistance, properties->m_loopMode == 1); + return 0; + } + + bool randomStart = properties->m_group != 1 && properties->m_group != 5 && !properties->m_noRandomStart; + + if (position) { + if (!sound->Create3D(file, looping, def->m_loadSoundGroup, def->m_soundGroup, randomStart, properties->m_streaming, properties->m_priority, properties->m_software, properties->m_coneInsideAngle, properties->m_coneOutsideAngle, properties->m_coneOutsideVolume, properties->m_coneOrientation)) { + return 16; + } + + sound->Set3DPosition(*position); + sound->Set3DMinMaxDistance(def->m_minDistance, properties->m_maxDistance > -1.0f ? properties->m_maxDistance : def->m_distanceCutoff); + } else if (!sound->Create2D(file, looping, def->m_loadSoundGroup, def->m_soundGroup, randomStart, properties->m_streaming, properties->m_reverb, properties->m_priority, properties->m_decodeBufferSize)) { + return 16; + } + + sound->SetChannelGroup(SI2::s_channelGroupNames[properties->m_group], properties->m_group != 3); + + SI2SoundUserData* userData = new (SMemAlloc(sizeof(SI2SoundUserData), __FILE__, __LINE__, 0)) SI2SoundUserData(); + userData->m_name = def->m_name ? def->m_name : ""; + userData->m_soundKitId = soundKitId; + userData->m_def = def; + userData->m_advancedId = advancedId; + userData->m_group = properties->m_group; + sound->SetUserData(userData); + + float volume; + + if (properties->m_volume < 0.0f || properties->m_volume > 1.0f) { + volume = def->m_volume * properties->m_volumeScale; + + if (def->m_flags & 0x800) { + CRange range; + range.m_l = -0.15f; + range.m_h = 0.15f; + volume = range.Random(g_rndSeed) + volume; + } + } else { + volume = properties->m_volume; + } + + sound->SetVolume(volume); + + if (def->m_flags & 0x400) { + CRange range; + range.m_l = 0.85f; + range.m_h = 1.15f; + sound->SetPitch(range.Random(g_rndSeed)); + } + + if (properties->m_fadeInTime >= 0.0f) { + sound->SetFadeInTime(properties->m_fadeInTime); + } + + if (properties->m_fadeOutTime >= 0.0f) { + sound->SetFadeOutTime(properties->m_fadeOutTime); + } + + SI2::s_channelGroupNumSounds[properties->m_group]++; + sound->SetFinishedCallback(SI2::SoundFinished, nullptr); + + if (def->m_flags & 0x20) { + uint32_t i; + + for (i = 0; i < SI2::s_suppressors.Count(); i++) { + if (!SI2::s_suppressors[i]) { + SI2::s_suppressors[i] = soundKitId; + break; + } + } + + if (i >= SI2::s_suppressors.Count()) { + *SI2::s_suppressors.New() = soundKitId; + } + } + + if (properties->m_useDspChain) { + sound->SetAttachCustomDSPChainCallback(SI2::DSP_AttachCustomDspChain, properties->m_dspChainName); + } + + sound->CompleteNonBlockingLoad(); + + if (soundId) { + *soundId = sound->GetID(); + } + + sound->Play(); + return 0; +} + +// VERIFY: 4ec0a358 manual +// OFFSET: 0x004C7140 +int32_t SI2ZoneSoundPair::Transition(int32_t soundKitId, int32_t type, SE2SoundKitProperties* properties, int32_t immediate, float fadeOutTime) { + if (type >= 11) { + SI2::StopSound(&this->m_sounds[this->m_current].m_object, 0, -1.0f, 1); + this->m_sounds[this->m_current].m_type = type; + this->m_sounds[this->m_current].m_soundKitId = 0; + return 18; + } + + if (immediate) { + SI2::StopSound(&this->m_sounds[this->m_current].m_object, 1, -1.0f, 1); + SI2::StopSound(&this->m_sounds[this->m_next].m_object, 1, -1.0f, 1); + + int32_t result = SI2::PlaySoundKit(soundKitId, nullptr, &this->m_sounds[this->m_current].m_object, properties, 0, nullptr, 1, 0); + + if (!result) { + this->m_sounds[this->m_current].m_soundKitId = soundKitId; + this->m_sounds[this->m_current].m_type = type; + return 0; + } + + return result; + } + + if (soundKitId == this->m_sounds[this->m_current].m_soundKitId && this->m_sounds[this->m_current].m_object.m_sound.IsPlaying()) { + return 15; + } + + if (soundKitId == this->m_sounds[this->m_next].m_soundKitId && this->m_sounds[this->m_next].m_object.m_sound.IsPlaying()) { + if (fadeOutTime >= 0.0f) { + this->m_sounds[this->m_current].m_object.m_sound.SetFadeOutTime(fadeOutTime); + } + + this->m_sounds[this->m_current].m_object.m_sound.FadeOutNow(); + + if (properties) { + this->m_sounds[this->m_next].m_object.m_sound.SetFadeInTime(properties->m_fadeInTime); + } + + this->m_sounds[this->m_next].m_object.m_sound.FadeInNow(); + + uint32_t current = this->m_current; + this->m_next = current; + this->m_current = 1 - current; + return 21; + } + + SI2::StopSound(&this->m_sounds[this->m_next].m_object, 0, -1.0f, 1); + + if (fadeOutTime >= 0.0f) { + this->m_sounds[this->m_current].m_object.m_sound.SetFadeOutTime(fadeOutTime); + } + + this->m_sounds[this->m_current].m_object.m_sound.FadeOutNow(); + + int32_t result = SI2::PlaySoundKit(soundKitId, nullptr, &this->m_sounds[this->m_next].m_object, properties, 0, nullptr, 1, 0); + + if (!result) { + this->m_sounds[this->m_next].m_soundKitId = soundKitId; + this->m_sounds[this->m_next].m_type = type; + + uint32_t current = this->m_current; + this->m_next = current; + this->m_current = 1 - current; + return 0; + } + + return result; +} + +// VERIFY: 212be192 auto +// OFFSET: 0x004C7410 +SE2SoundKitObject::SE2SoundKitObject() { + this->m_advancedId = 0; + this->unk_0010 = 0; +} + +// VERIFY: 19a1e756 auto +// OFFSET: 0x004C7440 +SE2SoundKitObject::~SE2SoundKitObject() { + if (this->m_advancedId) { + SI2::StopAdvancedSound(this->m_advancedId); + } +} + +// VERIFY: cf497004 auto +// OFFSET: 0x004C74A0 +int32_t SI2::PlaySoundKit(const char* name, const C3Vector* position, SE2SoundKitObject* object, SE2SoundKitProperties* properties) { + if (!SE2::IsInitialized()) { + return 17; + } + + int32_t soundKitId = SI2::LookupSoundKitId(name); + + if (!soundKitId) { + return 7; + } + + return SI2::PlaySoundKit(soundKitId, position, object, properties, 0, nullptr, 1, 0); +} + +// OFFSET: 0x004C74F0 +int32_t SI2::ChaosModeUpdate(const void* data, void* param) { + static CVar* s_chaosMode = CVar::Lookup("Sound_ChaosMode"); + + int32_t mode = 0; + + if (s_chaosMode) { + mode = s_chaosMode->m_intValue; + } + + static uint32_t s_maxSoundKitId = g_soundEntriesDB.m_maxID; + + C3Vector position; + position.x = 0.0f; + position.y = 0.0f; + position.z = 0.0f; + + uint32_t soundKitId = static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32); + + static SE2SoundKitObject s_object2D; + static SE2SoundKitObject s_object3D; + static SE2SoundKitObject s_loopObjects[80]; + static uint32_t s_lastTime = OsGetAsyncTimeMs(); + + uint32_t now = OsGetAsyncTimeMs(); + s_chaosElapsedMs += now - s_lastTime; + float elapsed = static_cast(now - s_lastTime) * 0.001f; + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_volumeScale = 0.3f; + properties.m_loopMode = 2; + properties.m_streaming = false; + properties.m_blockMusicFiles = 1; + + SE2SoundKitProperties loopProperties; + loopProperties.ResetToDefaults(); + loopProperties.m_volumeScale = 0.3f; + loopProperties.m_loopMode = 1; + loopProperties.m_streaming = false; + loopProperties.m_blockMusicFiles = 1; + + switch (mode) { + case 2: + if (s_chaosElapsedMs < 100) { + break; + } + + properties.m_streaming = true; + position = RandomListenerOffset(); + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), &position, nullptr, &properties, 0, nullptr, 1, 0); + + case 1: + if (s_chaosElapsedMs >= 100) { + properties.m_streaming = false; + position = RandomListenerOffset(); + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), &position, nullptr, &properties, 0, nullptr, 1, 0); + s_chaosElapsedMs = 0; + } + + break; + + case 4: + SI2::PlaySoundKit(soundKitId, nullptr, &s_object2D, &properties, 0, nullptr, 1, 0); + SI2::StopSound(&s_object2D, 1, -1.0f, 1); + SI2::PlaySoundKit(soundKitId, nullptr, &s_object3D, &properties, 0, nullptr, 1, 0); + SI2::StopSound(&s_object3D, 1, -1.0f, 1); + + case 3: + SI2::PlaySoundKit(soundKitId, nullptr, &s_object2D, &properties, 0, nullptr, 1, 0); + SI2::StopSound(&s_object2D, 1, -1.0f, 1); + position = RandomListenerOffset(); + SI2::PlaySoundKit(soundKitId, &position, &s_object3D, &properties, 0, nullptr, 1, 0); + SI2::StopSound(&s_object3D, 1, -1.0f, 1); + break; + + case 5: + s_chaosTimer += elapsed; + + if (s_chaosTimer <= 1.0f) { + break; + } + + for (int32_t i = 80; i; i--) { + SI2::PlaySoundKit(soundKitId, nullptr, nullptr, &properties, 0, nullptr, 1, 0); + } + + s_chaosTimer = 0.0f; + break; + + case 6: + s_chaosTimer += elapsed; + + if (s_chaosTimer <= 1.0f) { + break; + } + + for (int32_t i = 80; i; i--) { + position = RandomListenerOffset(); + SI2::PlaySoundKit(soundKitId, &position, nullptr, &properties, 0, nullptr, 1, 0); + } + + s_chaosTimer = 0.0f; + break; + + case 7: + s_chaosTimer += elapsed; + + if (s_chaosTimer <= 1.0f) { + break; + } + + for (SE2SoundKitObject* object = s_loopObjects; object < &s_loopObjects[80]; object++) { + if (!object->m_sound.IsPlaying()) { + position = RandomListenerOffset(); + SI2::PlaySoundKit(soundKitId, &position, object, &loopProperties, 0, nullptr, 1, 0); + } + } + + s_chaosTimer = 0.0f; + break; + + case 8: + s_chaosTimer += elapsed; + + if (s_chaosTimer <= 0.05f) { + break; + } + + printf("----------playing...\n"); + SI2::PlaySoundFile("Data\\Alert.mp3", 4); + s_chaosTimer = 0.0f; + break; + + case 9: + s_chaosRestartTimer += elapsed; + + if (s_chaosRestartTimer <= 10.0f) { + break; + } + + DebugLog("##RESTART SOUND ENGINE!!\n"); + SI2::ShutDown(1); + SI2::Init(1); + s_chaosRestartTimer = 0.0f; + + { + static CVar* s_chaosMode9 = CVar::Lookup("Sound_ChaosMode"); + s_chaosMode9->Set("9", true, false, false, true); + } + + break; + + case 10: + s_chaosRestartTimer += elapsed; + + if (s_chaosElapsedMs < 100) { + break; + } + + s_chaosElapsedMs = 0; + position = RandomListenerOffset(); + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), &position, nullptr, &properties, 0, nullptr, 1, 0); + position = RandomListenerOffset(); + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), &position, nullptr, &properties, 0, nullptr, 1, 0); + + if (s_chaosRestartTimer <= 10.0f) { + break; + } + + DebugLog("##RESTART SOUND ENGINE!!\n"); + SI2::ShutDown(1); + SI2::Init(1); + s_chaosRestartTimer = 0.0f; + + { + static CVar* s_chaosMode10 = CVar::Lookup("Sound_ChaosMode"); + s_chaosMode10->Set("10", true, false, false, true); + } + + break; + + case 13: + if (s_chaosElapsedMs < 100) { + break; + } + + properties.m_streaming = true; + position = RandomListenerOffset(); + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), &position, nullptr, &properties, 0, nullptr, 1, 0); + properties.m_streaming = false; + position = RandomListenerOffset(); + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), &position, nullptr, &properties, 0, nullptr, 1, 0); + + case 12: + if (s_chaosElapsedMs < 100) { + break; + } + + properties.m_streaming = true; + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), nullptr, nullptr, &properties, 0, nullptr, 1, 0); + + case 11: + if (s_chaosElapsedMs >= 100) { + properties.m_streaming = false; + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), nullptr, nullptr, &properties, 0, nullptr, 1, 0); + s_chaosElapsedMs = 0; + } + + break; + + case 14: { + s_chaosRestartTimer += elapsed; + + if (s_chaosElapsedMs < 100) { + break; + } + + s_chaosElapsedMs = 0; + uint32_t sameId = static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32); + + for (int32_t i = 20; i; i--) { + position = RandomListenerOffset(); + SI2::PlaySoundKit(sameId, &position, nullptr, &properties, 0, nullptr, 1, 0); + } + + position = RandomListenerOffset(); + SI2::PlaySoundKit(static_cast((static_cast(CRandom::uint32_(g_rndSeed)) * s_maxSoundKitId) >> 32), &position, nullptr, &properties, 0, nullptr, 1, 0); + + if (s_chaosRestartTimer <= 10.0f) { + break; + } + + DebugLog("##RESTART SOUND ENGINE!!\n"); + SI2::ShutDown(1); + SI2::Init(1); + s_chaosRestartTimer = 0.0f; + + static CVar* s_chaosMode14 = CVar::Lookup("Sound_ChaosMode"); + s_chaosMode14->Set("14", true, false, false, true); + break; + } + + case 15: { + int32_t ids[3] = { 13061, 15969, 12173 }; + + for (int32_t i = 0; i < 8; i++) { + position = RandomListenerOffset(); + SI2::PlaySoundKit(ids[(static_cast(CRandom::uint32_(g_rndSeed)) * 3) >> 32], &position, &s_object3D, &properties, 0, nullptr, 1, 0); + } + + break; + } + + default: + break; + } + + s_lastTime = now; + return 1; +} + +// VERIFY: 3e5c36df auto +// OFFSET: 0x004C82E0 +int32_t SI2::Init(int32_t restart) { + if (CmdLineGetBool(static_cast(26))) { + SI2::RegisterSoundEngineCVars(); + SI2::RegisterCVars(); + return 17; + } + + if (!restart) { + SI2::CreateVSoundLookup(); + SI2::InitFootstepSounds(); + SI2::InitEmoteSounds(); + SI2::InitWeaponImpactCombatSounds(); + SI2::InitWeaponSwingCombatSounds(); + SI2::RegisterSoundEngineCVars(); + } + + int32_t enableReverb = 0; + int32_t enableSoftwareHRTF = 0; + int32_t numChannels = 4; + + static CVar* s_enableReverb = CVar::Lookup("Sound_EnableReverb"); + + if (s_enableReverb) { + enableReverb = s_enableReverb->m_intValue; + } + + static CVar* s_enableSoftwareHRTF = CVar::Lookup("Sound_EnableSoftwareHRTF"); + + if (s_enableSoftwareHRTF) { + enableSoftwareHRTF = s_enableSoftwareHRTF->m_intValue; + } + + static CVar* s_numChannels = CVar::Lookup("Sound_NumChannels"); + + if (s_numChannels) { + numChannels = s_numChannels->m_intValue; + } + + int32_t outputDriverIndex = 0; + const char* outputDriverName = ""; + + static CVar* s_outputDriverIndex = CVar::Lookup("Sound_OutputDriverIndex"); + + if (s_outputDriverIndex) { + outputDriverIndex = s_outputDriverIndex->m_intValue; + } + + static CVar* s_outputDriverName = CVar::Lookup("Sound_OutputDriverName"); + + if (s_outputDriverName) { + outputDriverName = s_outputDriverName->m_stringValue.m_str; + } + + SE2::Init(512, SI2::GetObjectPosition, enableReverb, enableSoftwareHRTF, &numChannels, &outputDriverIndex, outputDriverName, SI2::GetSoundVolume, restart); + SI2::ClearSuppressors(); + + if (s_outputDriverIndex) { + char value[32]; + SStrPrintf(value, sizeof(value), "%d", outputDriverIndex); + s_outputDriverIndex->Set(value, true, false, false, true); + } + + static CVar* s_masterVolume = CVar::Lookup("Sound_MasterVolume"); + + if (s_masterVolume) { + SE2::SetMasterVolume(s_masterVolume->m_floatValue); + } + + EventRegister(EVENT_ID_POLL, SI2::UpdateAdvancedSounds); + EventRegister(EVENT_ID_FOCUS, SI2::OnFocusChanged); + SI2::RegisterCVars(); + + if (!restart) { + SI2::InitSoundKitLookup(); + SI2::InitWorldStateZoneSoundOverrides(); + SI2::InitZoneSoundOverrides(); + } + + SI2::CreateSoundGroups(); + + if (CmdLineGetBool(static_cast(27))) { + EventRegister(EVENT_ID_POLL, SI2::ChaosModeUpdate); + } + + SE2::SetDeviceChangeCallback(SI2::RegisterDeviceChangeHandler); + + static CVar* s_enableDSPEffects = CVar::Lookup("Sound_EnableDSPEffects"); + + if (s_enableDSPEffects->m_intValue) { + SI2::DSP_Init(); + } + + return 0; +} diff --git a/WoW/Source/SoundInterface/SoundInterface2.h b/WoW/Source/SoundInterface/SoundInterface2.h new file mode 100644 index 0000000..3e312f3 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2.h @@ -0,0 +1,246 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2_H + +#include +#include +#include "Engine/Source/SoundEngine/SoundEngine.h" +#include "Engine/Source/Storm/H/stpl.h" +#include "Engine/Source/Tempest/C3Vector.h" + +class CGUnit_C; +class CGUnitVirtualItem; +class CVar; +class SoundEntriesAdvancedRec; +class SE2SoundKitObject; +class SE2SoundKitProperties; +class VSOUNDKITDEF; + +class SE2SoundKitProperties { + public: + /* 0000 */ int32_t m_group; + /* 0004 */ float m_volume; + /* 0008 */ float m_volumeScale; + /* 000C */ int32_t m_fileIndex; + /* 0010 */ float m_fadeInTime; + /* 0014 */ float m_fadeOutTime; + /* 0018 */ int32_t m_selectMode; + /* 001C */ int32_t m_loopMode; + /* 0020 */ int32_t m_priority; + /* 0024 */ int32_t m_suppressorMode; + /* 0028 */ uint32_t m_decodeBufferSize; + /* 002C */ float m_maxDistance; + /* 0030 */ int32_t m_maxAudibleBehavior; + /* 0034 */ float m_muteFadeSpeed; + /* 0038 */ bool m_streaming; + /* 003C */ int32_t m_reverb; + /* 0040 */ int32_t m_noRandomStart; + /* 0044 */ int32_t m_blockMusicFiles; + /* 0048 */ int32_t m_software; + /* 004C */ float m_coneInsideAngle; + /* 0050 */ float m_coneOutsideAngle; + /* 0054 */ float m_coneOutsideVolume; + /* 0058 */ const C3Vector* m_coneOrientation; + /* 005C */ int32_t m_checkStreaming; + /* 0060 */ int32_t m_useDspChain; + /* 0064 */ char m_dspChainName[128]; + /* 00E4 */ int32_t m_forceLoop; + + void ResetToDefaults(); +}; + +class SE2SoundKitObject { + public: + /* 0000 */ TSLink m_link; + /* 0008 */ SESound m_sound; + /* 000C */ uint32_t m_advancedId; + /* 0010 */ uint32_t unk_0010; + + SE2SoundKitObject(); + ~SE2SoundKitObject(); +}; + +class SI2SoundUserData : public SESoundUserData { + public: + /* 0004 */ const char* m_name; + /* 0008 */ int32_t m_soundKitId; + /* 000C */ VSOUNDKITDEF* m_def; + /* 0010 */ int32_t m_group; + /* 0014 */ uint32_t unk_0014; + /* 0018 */ uint32_t m_advancedId; + + virtual ~SI2SoundUserData(); + virtual void Release(); + + SI2SoundUserData(); +}; + +class SI2 { + public: + static const char s_channelGroupNames[18][32]; + static const int32_t s_channelGroupMaxSounds[18]; + static int32_t s_channelGroupNumSounds[18]; + static TSGrowableArray s_suppressors; + static int32_t sm_bPlayerInside; + static int32_t sm_bCameraIsUnderwater; + static int32_t sm_bUnderwaterChanged; + static uint32_t sm_nextZoneMusicTime; + static int32_t sm_bLuaMusicPlaying; + static TSGrowableArray sm_aIntroMusicNextValidPlayTime; + + static int32_t AddAdvancedSound(SoundEntriesAdvancedRec* rec, int32_t soundKitId, const C3Vector* position, const C3Vector* orientation, SE2SoundKitObject* object, int32_t quickFade, int32_t a7, int32_t checkDistance, int32_t forceLoop); + static void AIMusicFinished(SESound* sound, void* param); + static void ApplyReverbSettings(); + static int32_t AttachToObject(SE2SoundKitObject* object, uint64_t guid); + static int32_t ChaosModeUpdate(const void* data, void* param); + static void ClearSuppressors(); + static void ClearSuppressorSounds(); + static void CreateSoundGroups(); + static void CreateVSoundLookup(); + static int32_t CreditsMusicUpdate(const void* data, void* param); + static void DestroyVSoundLookup(); + static void Detach(SE2SoundKitObject* object); + static void DSP_AttachCustomDspChain(FMOD::Channel* channel, char* name); + static void DSP_CreateDsp(const char* name, int32_t type, const float* params); + static void DSP_Init(); + static void DSP_MakeDSPsExpire(float elapsed); + static void DSP_ShutDown(); + static void FreeEmoteSounds(); + static void FreeFootstepSounds(); + static void FreeSoundKitDefs(); + static void FreeWorldStateZoneSoundOverrides(); + static void FreeZoneIntros(); + static void FreeZoneSoundOverrides(); + static float GetChannelGroupVolume(int32_t group); + static int32_t GetDesiredAmbienceKitID(int32_t* type); + static int32_t GetDesiredMusicKitID(int32_t* type, int32_t* silenceMin, int32_t* silenceMax); + static bool GetInputDriverName(int32_t index, char* name, int32_t nameLength, int32_t chatSystem); + static bool GetInputDriverName_Cached(int32_t index, char* name, int32_t nameLength, int32_t chatSystem); + static int32_t GetListenerPosition(C3Vector* position); + static int32_t GetNumInputDrivers(int32_t chatSystem); + static int32_t GetNumInputDrivers_Cached(int32_t chatSystem); + static int32_t GetNumOutputDrivers(int32_t chatSystem); + static int32_t GetNumOutputDrivers_Cached(int32_t chatSystem); + static int32_t GetNumSoundsInSoundKit(int32_t soundKitId); + static bool GetObjectPosition(uint64_t guid, C3Vector* position); + static bool GetOutputDriverName(int32_t index, char* name, int32_t nameLength, int32_t chatSystem); + static bool GetOutputDriverName_Cached(int32_t index, char* name, int32_t nameLength, int32_t chatSystem); + static VSOUNDKITDEF* GetSoundKitDef(int32_t soundKitId); + static int32_t GetSoundKitUsage(int32_t soundKitId); + static float GetSoundVolume(SESoundUserData* userData); + static int32_t GetTextEmoteSoundID(uint32_t emotesTextId, uint32_t race, uint32_t sex); + static int32_t GetTextEmoteSoundIndex(uint32_t emotesTextId, uint32_t race, uint32_t sex); + static int32_t GetZoneReverb(); + static int32_t GetZoneSoundOverride(int32_t mapId, int32_t chunkX, int32_t chunkY, int32_t subchunkX, int32_t subchunkY, int32_t* zoneIntroMusicId, int32_t* zoneMusicId, int32_t* soundAmbienceId, int32_t* soundProviderPreferencesId); + static int32_t GlueMusicUpdate(const void* data, void* param); + static int32_t HandleSoundDeviceChange(const void* data, void* param); + static int32_t HandleWaterSounds(const void* data, void* param); + static int32_t Init(int32_t restart); + static void InitEmoteSounds(); + static void InitFootstepSounds(); + static void InitSoundKitLookup(); + static void InitVocalErrorSounds(int32_t race, uint32_t sex); + static void InitWeaponImpactCombatSounds(); + static void InitWeaponSwingCombatSounds(); + static void InitWorldStateZoneSoundOverrides(); + static void InitZoneIntros(); + static void InitZoneSoundOverrides(); + static void InitZoneSoundsHandler(); + static void IntroMusicFinished(SESound* sound, void* param); + static int32_t IntroMusicOkToPlay(int32_t soundKitId, int32_t type); + static int32_t IsAdvancedSoundNear(int32_t soundKitId, const C3Vector* position); + static bool IsLooping(SE2SoundKitObject* object); + static bool IsPlaying(SE2SoundKitObject* object); + static uint32_t IsSoundKitLooping(int32_t soundKitId); + static int32_t IsTooCloseToExistingSoundKit(int32_t soundKitId, const C3Vector* position); + static int32_t IsUnderwater(); + static int32_t LookupSoundKitId(const char* name); + static void MarkAdvancedSoundStopped(uint32_t id); + static int32_t OnFocusChanged(const void* data, void* param); + static void PlayAIMusic(int32_t soundKitId); + static int32_t PlayFoleySound(int32_t materialId, const C3Vector* position, int32_t self); + static void PlayFootstepSound(int32_t footstepId, const C3Vector* position, int32_t terrainType, int32_t splash, int32_t loud, CGUnit_C* unit); + static void PlayHitSound(const CGUnitVirtualItem* weapon, int32_t impactType, int32_t crit, const C3Vector* position, int32_t self); + static void PlayItemSound(int32_t type, int32_t displayId); + static int32_t PlayMissedSound(bool oneHand, const C3Vector* position, int32_t self); + static void PlayParrySound(const CGUnitVirtualItem* weapon, const CGUnitVirtualItem* defender, int32_t crit, const C3Vector* position, int32_t self); + static int32_t PlaySheatheSound(const CGUnitVirtualItem* item, int32_t sheathe, const C3Vector* position, int32_t self); + static int32_t PlaySoundFile(const char* filename, int32_t group); + static int32_t PlaySoundKit(const char* name, const C3Vector* position, SE2SoundKitObject* object, SE2SoundKitProperties* properties); + static int32_t PlaySoundKit(int32_t soundKitId, const C3Vector* position, SE2SoundKitObject* object, SE2SoundKitProperties* properties, uint32_t advancedId, uint32_t* soundId, int32_t checkDistance, int32_t keepPlaying); + static int32_t PlayUISound(int32_t soundKitId); + static int32_t PlayWeaponSwooshSound(int32_t type, int32_t crit, const C3Vector* position, int32_t quiet, int32_t self); + static void RegisterCVars(); + static void RegisterDeviceChangeHandler(); + static void RegisterScriptFunctions(); + static void RegisterSoundEngineCVars(); + static void ReleaseSoundGroups(); + static int32_t ResetSoundKitVariants(const char* name); + static int32_t Set3DPosition(SE2SoundKitObject* object, const C3Vector* position); + static void SetAdvancedSoundPosition(uint32_t id, const C3Vector* position); + static void SetChannelGroupVolume(int32_t group, float volume); + static int32_t SetListenerAttributes(const C3Vector* position, const C3Vector* forward, const C3Vector* up, const C3Vector* velocity); + static void SetOverrideZoneSounds(int32_t soundAmbienceId, int32_t zoneMusicId); + static void SetPitch(SE2SoundKitObject* object, float pitch); + static void SetPlayerInside(bool inside); + static void SetUnderwaterStatus(int32_t underwater); + static int32_t SetVolume(SE2SoundKitObject* object, float volume); + static void SetWeatherKitID(int32_t soundKitId); + static void SetZoneAmbienceID(int32_t type, int32_t soundAmbienceId); + static void SetZoneIntroMusicID(int32_t type, int32_t zoneIntroMusicId); + static void SetZoneMusicID(int32_t type, int32_t zoneMusicId); + static void SetZoneReverb(int32_t type, int32_t reverb); + static void SetZoneUnderwaterReverb(int32_t reverb); + static int32_t ShutDown(int32_t restart); + static void ShutdownZoneSoundsHandler(); + static void SoundFinished(SESound* sound, void* param); + static void StartCreditsMusic(const char* name); + static void StartGlueAmbience(const char* name, float fadeInTime); + static void StartGlueMusic(const char* name); + static void StopAdvancedSound(uint32_t id); + static void StopAdvancedSound(uint32_t id, int32_t remove, float fadeOutTime); + static void StopAIMusic(); + static void StopAllMusic(); + static void StopAllSounds(); + static void StopAllSounds(float fadeOutTime); + static void StopCreditsMusic(); + static void StopGlueAmbience(float fadeOutTime); + static void StopGlueMusic(float fadeOutTime); + static void StopLuaMusic(); + static int32_t StopSound(SE2SoundKitObject* object, int32_t immediate, float fadeOutTime, int32_t stopAdvanced); + static void StopZoneAmbience(); + static void UnregisterScriptFunctions(); + static int32_t UpdateAdvancedSounds(const void* data, void* param); + static int32_t UpdateZoneSoundsForWorldState(int32_t areaId, int32_t zoneId, int32_t wmoAreaId, int32_t wmoGroupAreaId, int32_t inside); + static void UpdateDucking(int32_t elapsed); + static void UpdateReverb(); + static void ValidateOutputDriver(); + static void ValidateVoiceChatInputDriver(); + static void ValidateVoiceChatOutputDriver(); + static void VoiceChat_ActivatePrimaryCaptureCallback(); + static void VoiceChat_AmplifyMicrophoneInput(int16_t* data, uint32_t samples); + static void VoiceChat_CleanUpLoopbackSound(); + static int32_t VoiceChat_CreateChatSound(SE2SoundKitObject* object, SEStreamCallbacks* callbacks, int32_t chatSystem); + static void VoiceChat_DestroyChatSystem(); + static int32_t VoiceChat_GetCurrentMicrophoneSignalLevel(); + static void VoiceChat_InitCapture(float sampleRate); + static bool VoiceChat_IsPlayingLoopbackSound(); + static bool VoiceChat_IsRecordingLoopbackSound(); + static int32_t VoiceChat_IsVoiceChatInitialized(); + static int32_t VoiceChat_Play(SE2SoundKitObject* object); + static void VoiceChat_PlayLoopbackSound(); + static void VoiceChat_RecordLoopbackSound(int32_t seconds); + static void VoiceChat_SetCaptureDevice(int32_t index); + static void VoiceChat_SetOutputDevice(int32_t index); + static void VoiceChat_SetPrimaryCaptureCallback(SECaptureCallbacks* callbacks); + static void VoiceChat_ShutDownCapture(); + static void VoiceChat_StartCapture(); + static void VoiceChat_StopCapture(); + static void VoiceChat_StopPlayingLoopbackSound(); + static void VoiceChat_StopRecordingLoopbackSound(); + static void WaterShutdown(); + static int32_t ZoneMusicDelayElapsed(int32_t type); + static void ZoneMusicFinished(SESound* sound, void* param); + static int32_t ZoneSoundsUpdate(const void* data, void* param); +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.cpp b/WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.cpp new file mode 100644 index 0000000..057ef66 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.cpp @@ -0,0 +1,781 @@ +#include +#include +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.h" +#include "Engine/Source/SoundEngine/SoundEngine.h" +#include "Engine/Source/Storm/H/storm.h" +#include "Engine/Source/Tempest/CRandom.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Game/GameTime.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/SoundInterface/SoundInterface2Internal.h" + +// STATIC: 0x00AC390C +static uint32_t s_nextAdvancedId = 1; + +// STATIC: 0x00AC3924 +static TSList > s_suppressorSounds; + +// STATIC: 0x00B4AD24 +static HASHKEY_NONE s_vsoundKey; + +// STATIC: 0x00B4AD28 +static int32_t s_dayTime; + +// STATIC: 0x00B4AD2C +static TSHashTable* s_vsoundLookup; + +// STATIC: 0x00B4AD38 +static int32_t s_lastDayTime; + +// VERIFY: 3271634f auto +// OFFSET: 0x004C9CD0 +void SI2::DestroyVSoundLookup() { + if (s_vsoundLookup) { + delete s_vsoundLookup; + s_vsoundLookup = nullptr; + } +} + +// VERIFY: 80cb0ed8 auto +// OFFSET: 0x004C9CF0 +static int32_t IsInTimeWindow(SI2AdvancedSound* sound) { + int32_t offset = sound->m_randomOffset; + int32_t now = s_dayTime; + + if (sound->m_timeD + offset >= 86400000 && now < offset + sound->m_timeA) { + now += 86400000; + } + + return (sound->m_timeA + offset <= now && sound->m_timeD + offset >= now) || (!sound->m_timeA && !sound->m_timeB && !sound->m_timeC && !sound->m_timeD); +} + +// VERIFY: 42218333 auto +// OFFSET: 0x004C9D50 +static void StopAdvancedSoundObject(SI2AdvancedSound* sound, int32_t immediate) { + if (!sound) { + return; + } + + sound->m_stopped = 1; + + if (sound->m_object) { + SI2::StopSound(sound->m_object, immediate, -1.0f, 0); + } +} + +// VERIFY: b3211280 manual +// OFFSET: 0x004C9D90 +static int32_t RandomBetween(int32_t min, int32_t max) { + if (max > min) { + return min + static_cast((static_cast(static_cast(max - min)) * CRandom::uint32_(g_rndSeed)) >> 32); + } + + return max; +} + +// VERIFY: 3233d57a auto +// OFFSET: 0x004C9DC0 +int32_t SI2AdvancedSound::Play() { + SE2SoundKitProperties properties; + + if (this->m_usage) { + if (static_cast(this->m_usage - 1) > 1) { + return 0; + } + + properties.ResetToDefaults(); + properties.m_fadeInTime = 0.01f; + properties.m_fadeOutTime = 0.01f; + properties.m_group = this->m_volumeSliderCategory; + properties.m_coneInsideAngle = this->m_insideAngle; + properties.m_loopMode = 2; + properties.m_coneOutsideAngle = this->m_outsideAngle; + properties.m_maxAudibleBehavior = 1; + properties.m_streaming = false; + properties.m_coneOutsideVolume = this->m_outsideVolume; + properties.m_software = 1; + properties.m_coneOrientation = (0.0f == this->m_orientation.x && 0.0f == this->m_orientation.y && 0.0f == this->m_orientation.z) ? nullptr : &this->m_orientation; + + const C3Vector* position = (0.0f == this->m_position.x && 0.0f == this->m_position.y && 0.0f == this->m_position.z) ? nullptr : &this->m_position; + + return SI2::PlaySoundKit(this->m_soundKitId, position, this->m_object, &properties, this->m_id, &this->m_soundId, 1, 1); + } + + properties.ResetToDefaults(); + properties.m_loopMode = 1; + properties.m_maxAudibleBehavior = 0; + properties.m_streaming = true; + properties.m_software = 1; + + float fade = this->m_quickFade ? 0.7f : 3.0f; + properties.m_fadeInTime = fade; + properties.m_fadeOutTime = fade; + properties.m_group = this->m_volumeSliderCategory; + properties.m_coneInsideAngle = this->m_insideAngle; + properties.m_coneOutsideAngle = this->m_outsideAngle; + properties.m_coneOutsideVolume = this->m_outsideVolume; + properties.m_coneOrientation = (0.0f == this->m_orientation.x && 0.0f == this->m_orientation.y && 0.0f == this->m_orientation.z) ? nullptr : &this->m_orientation; + + return SI2::PlaySoundKit(this->m_soundKitId, &this->m_position, this->m_object, &properties, this->m_id, &this->m_soundId, 1, 1); +} + +// VERIFY: 762dbd2f manual +// OFFSET: 0x004C9FE0 +static float GetDuckVolume(int32_t group, SI2AdvancedSound* exclude) { + float volume = 1.0f; + + for (SuppressorSound* node = s_suppressorSounds.Head(); node; node = s_suppressorSounds.Next(node)) { + if (node->m_sound && node->m_sound == exclude) { + volume = 1.0f; + } else if (node->m_volume[group] < volume) { + volume = node->m_volume[group]; + } + } + + return volume; +} + +// VERIFY: 4f46a9dd auto +// OFFSET: 0x004CA040 +SI2AdvancedSound::SI2AdvancedSound() { + this->m_position.x = 0.0f; + this->m_position.y = 0.0f; + this->m_position.z = 0.0f; + this->m_orientation.x = 0.0f; + this->m_orientation.y = 0.0f; + this->m_orientation.z = 0.0f; + this->m_soundId = 0; + this->m_stopped = 0; + this->m_finished = 0; + this->m_innerRadius2d = 0.0f; + this->m_outerRadius2d = 0.0f; +} + +// VERIFY: d2749ee6 manual +// OFFSET: 0x004CA080 +SI2AdvancedSound::~SI2AdvancedSound() { + this->m_inRange = 0; + + for (SuppressorSound* node = s_suppressorSounds.Head(); node;) { + SuppressorSound* next = s_suppressorSounds.Next(node); + + if (node->m_sound == this) { + node->m_sound = nullptr; + } + + node = next; + } + + if (this->m_object) { + this->m_object->m_advancedId = 0; + } + + SE2SoundKitObject* object = this->m_object; + + if (object && !this->m_externalObject) { + delete object; + this->m_object = nullptr; + } +} + +// VERIFY: 1ee25e28 auto +// OFFSET: 0x004CA130 +int32_t SI2::IsAdvancedSoundNear(int32_t soundKitId, const C3Vector* position) { + if (!s_vsoundLookup) { + return 1; + } + + SE2::LockSoundList(); + + for (VSOUND_LOOKUP* node = s_vsoundLookup->m_fulllist.Head(); node; node = s_vsoundLookup->m_fulllist.Next(node)) { + SI2AdvancedSound* sound = node->m_sound; + + if (sound->m_rec->m_id == soundKitId) { + float dx = position->x - sound->m_position.x; + float dy = position->y - sound->m_position.y; + float dz = position->z - sound->m_position.z; + + if (dz * dz + dy * dy + dx * dx < 6.0f) { + SE2::UnlockSoundList(); + return 1; + } + } + } + + SE2::UnlockSoundList(); + return 0; +} + +// VERIFY: 5e6aafa6 manual +// OFFSET: 0x004CA1E0 +void SI2AdvancedSound::AddSuppressor() { + if ((this->m_duck[0] >= 0.0f && this->m_duck[0] < 1.0f) || (this->m_duck[1] >= 0.0f && this->m_duck[1] < 1.0f) || (this->m_duck[2] >= 0.0f && this->m_duck[2] < 1.0f)) { + for (SuppressorSound* node = s_suppressorSounds.Head(); node; node = s_suppressorSounds.Next(node)) { + if (node->m_sound == this) { + return; + } + } + + SuppressorSound* node = new (SMemAlloc(sizeof(SuppressorSound), __FILE__, __LINE__, 0)) SuppressorSound(); + node->m_sound = this; + node->m_fadeTime = this->m_timeToUnduck; + s_suppressorSounds.LinkToTail(node); + } +} + +// VERIFY: e5be26cc auto +// OFFSET: 0x004CA4E0 +void SI2::ClearSuppressors() { + s_suppressorSounds.Clear(); +} + +// VERIFY: bdd84a6b manual +// OFFSET: 0x004CA4F0 +void SI2::UpdateDucking(int32_t elapsed) { + C3Vector listener; + listener.x = 0.0f; + listener.y = 0.0f; + listener.z = 0.0f; + + SE2::GetListenerPosition(&listener); + + for (SuppressorSound* node = s_suppressorSounds.Head(); node;) { + SuppressorSound* next = s_suppressorSounds.Next(node); + + for (int32_t i = 0; i < 3; i++) { + SI2AdvancedSound* sound = node->m_sound; + float* volume = &node->m_volume[i]; + + if (sound) { + bool atOrigin = 0.0f == sound->m_position.x && 0.0f == sound->m_position.y && 0.0f == sound->m_position.z; + float dx = listener.x - sound->m_position.x; + float dy = listener.y - sound->m_position.y; + float dz = listener.z - sound->m_position.z; + float distance = sqrt(dz * dz + dy * dy + dx * dx); + node->m_distance = distance; + + if (atOrigin || distance < sound->m_innerRadiusOfInfluence || (distance < sound->m_outerRadiusOfInfluence && sound->m_inRange)) { + if (sound->m_duck[i] != *volume) { + int32_t time = sound->m_timeToDuck; + + if (time > 0) { + *volume = *volume - static_cast(elapsed) / time; + + if (*volume < node->m_sound->m_duck[i]) { + *volume = node->m_sound->m_duck[i]; + node->m_sound->m_inRange = 1; + continue; + } + } else { + *volume = sound->m_duck[i]; + } + } + + node->m_sound->m_inRange = 1; + } else { + sound->m_inRange = 0; + SI2AdvancedSound* removed = node->m_sound; + + for (SuppressorSound* other = s_suppressorSounds.Head(); other;) { + SuppressorSound* otherNext = s_suppressorSounds.Next(other); + + if (other->m_sound == removed) { + other->m_sound = nullptr; + } + + other = otherNext; + } + } + } else if (1.0f != *volume) { + int32_t time = node->m_fadeTime; + + if (time <= 0 || (*volume = static_cast(elapsed) / time + *volume) > 1.0f) { + *volume = 1.0f; + } + } + } + + if (!node->m_sound && 1.0f == node->m_volume[0] && 1.0f == node->m_volume[1] && 1.0f == node->m_volume[2]) { + delete node; + } + + node = next; + } +} + +// VERIFY: 2e8555db manual +// OFFSET: 0x004CA7B0 +int32_t SI2::UpdateAdvancedSounds(const void* data, void* param) { + int32_t now = static_cast(g_clientGameTime.GameTimeGetDayProgression() * 86400000.0f); + int32_t elapsed = now - s_lastDayTime; + s_dayTime = now; + + if (elapsed < 0) { + elapsed = 0; + } + + s_lastDayTime = now; + + SI2::UpdateDucking(elapsed); + + int32_t created = 0; + SE2::LockSoundList(); + + VSOUND_LOOKUP* node = s_vsoundLookup->m_fulllist.Head(); + + while (node) { + SI2AdvancedSound* sound = node->m_sound; + + if (sound->m_finished) { + VSOUND_LOOKUP* next = s_vsoundLookup->m_fulllist.Next(node); + s_vsoundLookup->DeleteNode(node); + node = next; + continue; + } + + SESound* object = sound->m_object ? &sound->m_object->m_sound : nullptr; + created = 0; + + if (object && object->IsPlaying()) { + if (!IsInTimeWindow(sound)) { + node = s_vsoundLookup->m_fulllist.Next(node); + + if (sound->m_usage) { + continue; + } + + int32_t immediate = sound->m_volume <= 0.0f; + sound->m_stopped = 1; + + if (sound->m_object) { + SI2::StopSound(sound->m_object, immediate, -1.0f, 0); + } + + continue; + } + + SI2SoundUserData* userData = static_cast(sound->m_object->m_sound.GetUserData()); + + if (!sound->m_usage && userData && userData->m_def->m_numFiles > 1 && sound->m_intervalMin > 0.0f && sound->m_intervalMax > 0.0f) { + sound->m_nextInterval -= elapsed; + + if (sound->m_nextInterval < 0) { + StopAdvancedSoundObject(sound, 0); + sound->Play(); + sound->m_nextInterval = RandomBetween(sound->m_intervalMin, sound->m_intervalMax); + } + } + + SESound* live = SE2::GetSoundFromID(node->m_sound->m_soundId, &created); + + if (live) { + float pan = 1.0f; + + if (node->m_sound->m_outerRadius2d > 0.0f) { + C3Vector listener; + listener.x = 0.0f; + listener.y = 0.0f; + listener.z = 0.0f; + SI2::GetListenerPosition(&listener); + + SI2AdvancedSound* advanced = node->m_sound; + float dx = listener.x - advanced->m_position.x; + float dy = listener.y - advanced->m_position.y; + float dz = listener.z - advanced->m_position.z; + float distanceSq = dz * dz + dy * dy + dx * dx; + float level; + + if (advanced->m_innerRadius2d * advanced->m_innerRadius2d < distanceSq) { + level = node->m_sound->m_outerRadius2d * node->m_sound->m_outerRadius2d < distanceSq ? 1.0f : (sqrt(distanceSq) - node->m_sound->m_innerRadius2d) / (node->m_sound->m_outerRadius2d - node->m_sound->m_innerRadius2d); + } else { + level = 0.0f; + } + + pan = level; + + if (!(node->m_sound->m_innerRadiusOfInfluence * node->m_sound->m_innerRadiusOfInfluence < distanceSq)) { + node->m_sound->AddSuppressor(); + pan = level; + } + } + + live->Set3DPanLevel(pan); + + if (created) { + live->Detach(); + delete live; + } + } + + if (sound->m_usage != 2 && (sound->m_timeA || sound->m_timeB || sound->m_timeC || sound->m_timeD)) { + int32_t offset = sound->m_randomOffset; + int32_t time = s_dayTime; + + if (sound->m_timeD + offset >= 86400000 && time < offset + sound->m_timeA) { + time += 86400000; + } + + if (time < offset + sound->m_timeB) { + sound->m_volume = static_cast(time - sound->m_timeA) / (sound->m_timeB - sound->m_timeA); + + if (sound->m_volume > 1.0f) { + sound->m_volume = 1.0f; + } + + if (sound->m_volume < 0.0f) { + sound->m_volume = 0.0f; + } + } else if (time < offset + sound->m_timeC) { + sound->m_volume = 1.0f; + } else { + sound->m_volume = 1.0f - static_cast(time - sound->m_timeC) / (sound->m_timeD - sound->m_timeC); + + if (sound->m_volume > 1.0f) { + sound->m_volume = 1.0f; + } + + if (sound->m_volume < 0.0f) { + sound->m_volume = 0.0f; + } + } + } + + node = s_vsoundLookup->m_fulllist.Next(node); + continue; + } + + SI2AdvancedSound* advanced = node->m_sound; + int32_t usage = advanced->m_usage; + + if (!advanced->m_object || usage == 2 || (!usage && advanced->m_stopped)) { + VSOUND_LOOKUP* next = s_vsoundLookup->m_fulllist.Next(node); + s_vsoundLookup->DeleteNode(node); + node = next; + continue; + } + + if (IsInTimeWindow(advanced)) { + if (!usage) { + node->m_sound->Play(); + } else if (usage == 1) { + node->m_sound->m_nextInterval -= elapsed; + + if (node->m_sound->m_nextInterval < 0) { + node->m_sound->Play(); + sound->m_nextInterval = RandomBetween(sound->m_intervalMin, sound->m_intervalMax); + } + } + } + + node = s_vsoundLookup->m_fulllist.Next(node); + } + + SE2::UnlockSoundList(); + return 1; +} + +// VERIFY: 3a7d0c7f manual +// OFFSET: 0x004CB160 +void SI2::CreateVSoundLookup() { + if (!s_vsoundLookup) { + s_vsoundLookup = new (SMemAlloc(sizeof(TSHashTable), __FILE__, __LINE__, 0)) TSHashTable(); + } +} + +// VERIFY: 00aa6854 auto +// OFFSET: 0x004CB1A0 +void SI2::MarkAdvancedSoundStopped(uint32_t id) { + SE2::LockSoundList(); + + VSOUND_LOOKUP* node = s_vsoundLookup->Ptr(id, s_vsoundKey); + + if (node) { + node->m_sound->m_finished = 1; + } + + SE2::UnlockSoundList(); +} + +// VERIFY: 4e03a953 auto +// OFFSET: 0x004CB1D0 +void SI2::StopAdvancedSound(uint32_t id) { + if (!id || !s_vsoundLookup) { + return; + } + + SE2::LockSoundList(); + + TSHashTable* lookup = s_vsoundLookup; + VSOUND_LOOKUP* node = lookup->Ptr(id, s_vsoundKey); + + if (node) { + lookup->DeleteNode(node); + } + + SE2::UnlockSoundList(); +} + +// VERIFY: 9c993a65 auto +// OFFSET: 0x004CB220 +float SI2::GetSoundVolume(SESoundUserData* userData) { + if (!userData) { + return 1.0f; + } + + SI2SoundUserData* data = static_cast(userData); + float volume = 1.0f; + SI2AdvancedSound* sound; + + if (s_vsoundLookup) { + SE2::LockSoundList(); + VSOUND_LOOKUP* node = s_vsoundLookup->Ptr(data->m_advancedId, s_vsoundKey); + SE2::UnlockSoundList(); + + if (node) { + sound = node->m_sound; + + if (sound) { + volume = sound->m_volume; + } + } else { + sound = nullptr; + } + } else { + sound = nullptr; + } + + int32_t group = data->m_group; + + if (!group || group >= 7) { + return GetDuckVolume(0, sound) * volume; + } + + if (group == 1) { + return GetDuckVolume(1, sound) * volume; + } + + if (group == 2) { + return GetDuckVolume(2, sound) * volume; + } + + return volume; +} + +// VERIFY: c3f6bde5 manual +// OFFSET: 0x004CB2D0 +void SI2::SetAdvancedSoundPosition(uint32_t id, const C3Vector* position) { + SE2::LockSoundList(); + + VSOUND_LOOKUP* node = s_vsoundLookup->Ptr(id, s_vsoundKey); + + if (node) { + node->m_sound->m_position = *position; + } + + SE2::UnlockSoundList(); +} + +// VERIFY: 4e1ff068 auto +// OFFSET: 0x004CB3B0 +void SI2::ClearSuppressorSounds() { + s_suppressorSounds.Clear(); + + if (!s_vsoundLookup) { + return; + } + + SE2::LockSoundList(); + + TSHashTable* lookup = s_vsoundLookup; + + for (VSOUND_LOOKUP* node = lookup->m_fulllist.Head(); node; node = lookup->m_fulllist.Head()) { + uint32_t id = node->m_sound->m_id; + + if (id && lookup) { + SI2::StopAdvancedSound(id); + lookup = s_vsoundLookup; + } + } + + SE2::UnlockSoundList(); +} + +// VERIFY: 524c166b auto +// OFFSET: 0x004CB440 +void SI2AdvancedSound::Stop(int32_t remove, float fadeOutTime) { + if (remove) { + SI2::StopAdvancedSound(this->m_id); + return; + } + + this->m_stopped = 1; + + if (this->m_object) { + if (fadeOutTime >= 0.0f) { + this->m_object->m_sound.SetFadeOutTime(fadeOutTime); + } + + this->m_object->m_sound.FadeOutNow(); + } +} + +// VERIFY: 8741a1fc auto +// OFFSET: 0x004CB4E0 +void SI2::StopAdvancedSound(uint32_t id, int32_t remove, float fadeOutTime) { + SE2::LockSoundList(); + + VSOUND_LOOKUP* node = s_vsoundLookup->Ptr(id, s_vsoundKey); + + if (node) { + node->m_sound->Stop(remove, fadeOutTime); + } + + SE2::UnlockSoundList(); +} + +// VERIFY: 87c34bf4 manual +// OFFSET: 0x004CB580 +int32_t SI2::AddAdvancedSound(SoundEntriesAdvancedRec* rec, int32_t soundKitId, const C3Vector* position, const C3Vector* orientation, SE2SoundKitObject* object, int32_t quickFade, int32_t a7, int32_t checkDistance, int32_t forceLoop) { + if (!rec) { + return 24; + } + + if (!s_vsoundLookup) { + return 17; + } + + C3Vector zero; + zero.x = 0.0f; + zero.y = 0.0f; + zero.z = 0.0f; + + if (!orientation) { + orientation = &zero; + } + + if (position && !quickFade && checkDistance && SI2::IsAdvancedSoundNear(rec->m_id, position)) { + return 15; + } + + SI2AdvancedSound* sound = new (SMemAlloc(sizeof(SI2AdvancedSound), __FILE__, __LINE__, 0)) SI2AdvancedSound(); + + if (!sound) { + return 22; + } + + if (object) { + sound->m_object = object; + sound->m_externalObject = 1; + } else { + sound->m_externalObject = 0; + sound->m_object = new (SMemAlloc(sizeof(SE2SoundKitObject), __FILE__, __LINE__, 0)) SE2SoundKitObject(); + + if (!sound->m_object) { + sound->~SI2AdvancedSound(); + SMemFree(sound, "delete", -1, 0); + return 22; + } + } + + sound->m_quickFade = quickFade; + sound->m_rec = rec; + sound->m_soundKitId = soundKitId; + sound->m_innerRadius2d = rec->m_innerRadius2d; + sound->m_outerRadius2d = rec->m_outerRadius2d; + sound->m_timeA = rec->m_timeA; + sound->m_timeB = rec->m_timeB; + sound->m_timeC = rec->m_timeC; + sound->m_timeD = rec->m_timeD; + + if (sound->m_timeB < sound->m_timeA) { + sound->m_timeB = rec->m_timeB + 86400000; + } + + if (sound->m_timeC < sound->m_timeB) { + sound->m_timeC = rec->m_timeC + 86400000; + } + + if (sound->m_timeD < sound->m_timeC) { + sound->m_timeD += 86400000; + } + + sound->m_randomOffsetRange = rec->m_randomOffsetRange; + sound->m_volume = 1.0f; + sound->m_randomOffset = RandomBetween(0, sound->m_randomOffsetRange); + sound->m_usage = forceLoop ? 0 : rec->m_usage; + sound->m_intervalMin = rec->m_timeIntervalMin; + sound->m_intervalMax = rec->m_timeIntervalMax; + sound->m_nextInterval = RandomBetween(sound->m_intervalMin, sound->m_intervalMax); + sound->m_volumeSliderCategory = rec->m_volumeSliderCategory; + sound->m_duck[0] = (rec->m_duckToSfx < 0.0f || rec->m_duckToSfx > 1.0f) ? 1.0f : rec->m_duckToSfx; + sound->m_duck[1] = (rec->m_duckToMusic < 0.0f || rec->m_duckToMusic > 1.0f) ? 1.0f : rec->m_duckToMusic; + sound->m_duck[2] = (rec->m_duckToAmbience < 0.0f || rec->m_duckToAmbience > 1.0f) ? 1.0f : rec->m_duckToAmbience; + sound->m_innerRadiusOfInfluence = rec->m_innerRadiusOfInfluence; + sound->m_outerRadiusOfInfluence = rec->m_outerRadiusOfInfluence; + + if (sound->m_outerRadiusOfInfluence < sound->m_innerRadiusOfInfluence) { + sound->m_innerRadiusOfInfluence = sound->m_outerRadiusOfInfluence; + } + + sound->m_inRange = 0; + sound->m_timeToDuck = rec->m_timeToDuck; + sound->m_timeToUnduck = rec->m_timeToUnduck; + sound->m_insideAngle = rec->m_insideAngle; + sound->m_outsideAngle = rec->m_outsideAngle; + + if (sound->m_outsideAngle < sound->m_insideAngle) { + sound->m_insideAngle = sound->m_outsideAngle; + } + + sound->m_outsideVolume = rec->m_outsideVolume; + + if (position) { + sound->m_position = *position; + } else { + sound->m_position.x = 0.0f; + sound->m_position.y = 0.0f; + sound->m_position.z = 0.0f; + } + + sound->m_orientation = *orientation; + sound->unk_0008 = a7; + + sound->m_id = s_nextAdvancedId; + sound->m_object->m_advancedId = s_nextAdvancedId; + s_nextAdvancedId++; + + uint32_t id = sound->m_id; + VSOUND_LOOKUP* node = s_vsoundLookup->InternalNewNode(id, 0, 0); + node->m_hashval = id; + node->m_sound = sound; + + if (sound->m_usage == 2) { + sound->Play(); + + if (SI2::IsPlaying(sound->m_object)) { + sound->AddSuppressor(); + } + } + + return 0; +} + +// INLINED +SuppressorSound::SuppressorSound() { + this->m_volume[0] = 1.0f; + this->m_volume[1] = 1.0f; + this->m_volume[2] = 1.0f; + this->m_sound = nullptr; + this->m_distance = 0.0f; + this->m_fadeTime = 1000; +} + +// INLINED +VSOUND_LOOKUP::~VSOUND_LOOKUP() { + if (this->m_sound) { + delete this->m_sound; + this->m_sound = nullptr; + } +} diff --git a/WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.h b/WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.h new file mode 100644 index 0000000..a65a5fe --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2AdvancedKitProperties.h @@ -0,0 +1,75 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2ADVANCEDKITPROPERTIES_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2ADVANCEDKITPROPERTIES_H + +#include +#include +#include "Engine/Source/Storm/H/stpl.h" +#include "Engine/Source/Tempest/C3Vector.h" + +class SE2SoundKitObject; +class SI2AdvancedSound; +class SoundEntriesAdvancedRec; + +class SI2AdvancedSound { + public: + /* 0000 */ TSLink m_link; + /* 0008 */ int32_t unk_0008; + /* 000C */ int32_t m_stopped; + /* 0010 */ int32_t m_finished; + /* 0014 */ SE2SoundKitObject* m_object; + /* 0018 */ int32_t m_externalObject; + /* 001C */ SoundEntriesAdvancedRec* m_rec; + /* 0020 */ int32_t m_soundKitId; + /* 0024 */ uint32_t m_soundId; + /* 0028 */ C3Vector m_position; + /* 0034 */ float m_innerRadius2d; + /* 0038 */ float m_outerRadius2d; + /* 003C */ int32_t m_timeA; + /* 0040 */ int32_t m_timeB; + /* 0044 */ int32_t m_timeC; + /* 0048 */ int32_t m_timeD; + /* 004C */ int32_t m_randomOffsetRange; + /* 0050 */ int32_t m_randomOffset; + /* 0054 */ float m_volume; + /* 0058 */ int32_t m_usage; + /* 005C */ int32_t m_nextInterval; + /* 0060 */ int32_t m_intervalMin; + /* 0064 */ int32_t m_intervalMax; + /* 0068 */ int32_t m_volumeSliderCategory; + /* 006C */ float m_duck[3]; + /* 0078 */ float m_innerRadiusOfInfluence; + /* 007C */ float m_outerRadiusOfInfluence; + /* 0080 */ int32_t m_inRange; + /* 0084 */ int32_t m_timeToDuck; + /* 0088 */ int32_t m_timeToUnduck; + /* 008C */ float m_insideAngle; + /* 0090 */ float m_outsideAngle; + /* 0094 */ float m_outsideVolume; + /* 0098 */ C3Vector m_orientation; + /* 00A4 */ int32_t m_quickFade; + /* 00A8 */ uint32_t m_id; + + SI2AdvancedSound(); + ~SI2AdvancedSound(); + void AddSuppressor(); + int32_t Play(); + void Stop(int32_t remove, float fadeOutTime); +}; + +class SuppressorSound : public TSLinkedNode { + public: + /* 0008 */ SI2AdvancedSound* m_sound; + /* 000C */ float m_volume[3]; + /* 0018 */ float m_distance; + /* 001C */ int32_t m_fadeTime; + + SuppressorSound(); +}; + +struct VSOUND_LOOKUP : public TSHashObject { + /* 0018 */ SI2AdvancedSound* m_sound; + + ~VSOUND_LOOKUP(); +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2CVars.cpp b/WoW/Source/SoundInterface/SoundInterface2CVars.cpp new file mode 100644 index 0000000..f0f0a1e --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2CVars.cpp @@ -0,0 +1,331 @@ +#include +#include +#include +#include +#include "Engine/Source/Base/CmdLine.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/ConsoleBase/IConsole.h" +#include "Engine/Source/Os/System.h" +#include "Engine/Source/SoundEngine/SoundEngine.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/Game/GameClient/ComSatClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/Ui/GameUI.h" + +// VERIFY: 416b0558 auto +// OFFSET: 0x004D0BC0 +static bool EnableReverbHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + if (SStrToInt(value)) { + SE2::EnableReverb(1); + SI2::ApplyReverbSettings(); + } else { + FMOD_REVERB_PROPERTIES properties = FMOD_PRESET_OFF; + SE2::SetReverb(&properties); + SE2::EnableReverb(0); + } + + return true; +} + +// VERIFY: 5dc4640a manual +// OFFSET: 0x004D0CB0 +static bool VoiceChatInputDriverIndexHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + int32_t index = SStrToInt(value); + char name[256]; + memset(name, 0, sizeof(name)); + + if (SE2::GetInputDriverName(index, name, sizeof(name), 1)) { + static CVar* s_inputDriverName = CVar::Lookup("Sound_VoiceChatInputDriverName"); + s_inputDriverName->Set(name, true, false, false, true); + } + + return true; +} + +// VERIFY: e67c8f37 manual +// OFFSET: 0x004D0D40 +static bool VoiceChatOutputDriverIndexHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + int32_t index = SStrToInt(value); + char name[256]; + memset(name, 0, sizeof(name)); + + if (SE2::GetOutputDriverName(index, name, sizeof(name), 1)) { + static CVar* s_outputDriverName = CVar::Lookup("Sound_VoiceChatOutputDriverName"); + s_outputDriverName->Set(name, true, false, false, true); + } + + return true; +} + +// VERIFY: 82450cd2 manual +// OFFSET: 0x004D0DD0 +static bool OutputDriverIndexHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + int32_t index = SStrToInt(value); + char name[256]; + memset(name, 0, sizeof(name)); + + if (SE2::GetOutputDriverName(index, name, sizeof(name), 0)) { + static CVar* s_outputDriverName = CVar::Lookup("Sound_OutputDriverName"); + s_outputDriverName->Set(name, true, false, false, true); + } + + return true; +} + +// VERIFY: 65821b05 auto +// OFFSET: 0x004D0E60 +static bool MasterVolumeHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + SE2::SetMasterVolume(SStrToFloat(value)); + return true; +} + +// VERIFY: 1f180752 auto +// OFFSET: 0x004D0E80 +static bool SFXVolumeHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + SE2::SetChannelGroupVolume(SI2::s_channelGroupNames[0], SStrToFloat(value)); + return true; +} + +// VERIFY: 8c1f3d6b auto +// OFFSET: 0x004D0EB0 +static bool MusicVolumeHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + SE2::SetChannelGroupVolume("MUSIC", SStrToFloat(value)); + SE2::SetChannelGroupVolume("SCRIPTMUSIC", SStrToFloat(value)); + return true; +} + +// VERIFY: de0d919f auto +// OFFSET: 0x004D0EF0 +static bool AmbienceVolumeHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + SE2::SetChannelGroupVolume("AMBIENCE", SStrToFloat(value)); + return true; +} + +// VERIFY: 8140baa9 auto +// OFFSET: 0x004D0F20 +static bool ChaosModeHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + ConsolePrintf("CHAOS!!"); + ConsolePrintf("Modes:"); + ConsolePrintf("0: Off"); + ConsolePrintf("1: Generate 1 random 3d sound per frame"); + ConsolePrintf("2: Generate 2 random 3d sounds per frame"); + ConsolePrintf("3: Start and stop 1 2d and 1 3d sound every frame"); + ConsolePrintf("4: Start and stop 2 2d and 2 3d sounds every frame"); + ConsolePrintf("5: Play the same random sound x20 (in 2d) every second"); + ConsolePrintf("6: Play the same random sound x20 (in 3d) every second"); + ConsolePrintf("7: Play the same random looping sound x20 (in 3d) every second"); + ConsolePrintf("8: Play Alert.mp3 from Data folder a lot"); + ConsolePrintf("9: Restart game sound system (NOT INCLUDING VOICE CHAT SYSTEM) every 10 seconds"); + ConsolePrintf(" ALERT! This mode breaks voice chat, and will cause a crash on game exit."); + ConsolePrintf("10: Mode 2 + Mode 9"); + ConsolePrintf("11: Generate 1 random 2d sound per frame"); + ConsolePrintf("12: Generate 2 random 2d sounds per frame"); + ConsolePrintf("13: Generate 2 random 2d sounds AND 2 random 3d sounds per frame"); + ConsolePrintf("14: Mode 10 + Mode 6"); + + int32_t mode = atol(value); + + static CVar* s_disableStreams = CVar::Lookup("Sound_DisableStreams"); + + if (s_disableStreams) { + if (!mode) { + s_disableStreams->Set("0", true, false, false, true); + return true; + } + + s_disableStreams->Set("1", true, false, false, true); + } + + return true; +} + +// VERIFY: 9f0ddfd9 auto +// OFFSET: 0x004D1050 +void SI2::RegisterSoundEngineCVars() { + CVar::Register("StartTalkingDelay", "", 0, "0.0", nullptr, 5, false, nullptr, false); + CVar::Register("StartTalkingTime", "", 0, "1.0", nullptr, 5, false, nullptr, false); + CVar::Register("StopTalkingDelay", "", 0, "0.0", nullptr, 5, false, nullptr, false); + CVar::Register("StopTalkingTime", "", 0, "2.0", nullptr, 5, false, nullptr, false); + CVar::Register("OutboundChatVolume", "The software amplification factor (0.0 - 2.0)", 0, "1.0", OutboundChatVolumeHandler, 5, false, nullptr, false); + CVar::Register("InboundChatVolume", "The volume of all other chat you hear (0.0 - 1.0)", 0, "1.0", InboundChatVolumeHandler, 5, false, nullptr, false); + CVar::Register("VoiceChatMode", "Push to talk(0) or voice activation(1)", 0, "0", VoiceChatModeHandler, 5, false, nullptr, false); + CVar::Register("VoiceActivationSensitivity", "Sensitivity of the microphone (0.0 - 1.0)", 0, "0.4", VoiceActivationSensitivityHandler, 5, false, nullptr, false); + CVar::Register("EnableMicrophone", "Enables the microphone so you can speak.", 0, "1", EnableMicrophoneHandler, 5, false, nullptr, false); + CVar::Register("EnableVoiceChat", "Enables the voice chat feature.", 0, "0", EnableVoiceChatHandler, 5, false, nullptr, false); + CVar::Register("VoiceChatSelfMute", "Turn off your ability to talk.", 0, "0", SelfMuteHandler, 5, false, nullptr, false); + CVar::Register("PushToTalkButton", "String representation of the Push-To-Talk button.", 0, "`", PushToTalkButtonHandler, 5, false, nullptr, false); + CVar::Register("Sound_OutputQuality", "sound quality, default 1 (medium)", 0, "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_NumChannels", "number of sound channels", 0, "32", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableReverb", "", 0, "0", EnableReverbHandler, 7, false, nullptr, false); + CVar::Register("Sound_EnableSoftwareHRTF", "", 0, "0", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_VoiceChatInputDriverIndex", "", 0, "0", VoiceChatInputDriverIndexHandler, 7, false, nullptr, false); + CVar::Register("Sound_VoiceChatInputDriverName", "", 0, "Primary Sound Capture Driver", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_VoiceChatOutputDriverIndex", "", 0, "0", VoiceChatOutputDriverIndexHandler, 7, false, nullptr, false); + CVar::Register("Sound_VoiceChatOutputDriverName", "", 0, "Primary Sound Driver", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_OutputDriverIndex", "", 0, "0", OutputDriverIndexHandler, 7, false, nullptr, false); + CVar::Register("Sound_OutputDriverName", "", 0, "Primary Sound Driver", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_DSPBufferSize", "sound buffer size, default 0", 0, "0", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableHardware", "Enables Hardware", 0, "0", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableMode2", "test", 0, "0", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableMixMode2", "test", 0, "0", nullptr, 7, false, nullptr, false); +} + +// VERIFY: 3f7da3da auto +// OFFSET: 0x004D13E0 +static bool EnableAllSoundHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + if (SStrToInt(value)) { + static CVar* s_enableSFX = CVar::Lookup("Sound_EnableSFX"); + static CVar* s_enableMusic = CVar::Lookup("Sound_EnableMusic"); + static CVar* s_enableAmbience = CVar::Lookup("Sound_EnableAmbience"); + + SE2::MuteChannelGroup(SI2::s_channelGroupNames[0], s_enableSFX->m_intValue == 0); + SE2::MuteChannelGroup("MUSIC", s_enableMusic->m_intValue == 0); + SE2::MuteChannelGroup("AMBIENCE", s_enableAmbience->m_intValue == 0); + return true; + } + + SE2::MuteChannelGroup(SI2::s_channelGroupNames[0], true); + SE2::MuteChannelGroup("MUSIC", true); + SE2::MuteChannelGroup("AMBIENCE", true); + return true; +} + +// VERIFY: d8927d35 manual +// OFFSET: 0x004D14E0 +static bool EnableSFXHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + CVar* enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + + if (enableAllSound) { + SE2::MuteChannelGroup(SI2::s_channelGroupNames[0], !SStrToInt(value) || !enableAllSound->m_intValue); + } + + return true; +} + +// VERIFY: 34387ca8 manual +// OFFSET: 0x004D1530 +static bool EnableAmbienceHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + CVar* enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + + if (enableAllSound) { + bool mute = !SStrToInt(value) || !enableAllSound->m_intValue || CGGameUI::m_inMovie; + SE2::MuteChannelGroup("AMBIENCE", mute); + + if (mute) { + SI2::StopZoneAmbience(); + } + } + + return true; +} + +// VERIFY: c5c182ec auto +// OFFSET: 0x004D1590 +static bool EnableMusicHandler(CVar* var, const char* oldValue, const char* value, void* arg) { + CVar* enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + + if (enableAllSound) { + bool mute = !SStrToInt(value) || !enableAllSound->m_intValue || CGGameUI::m_inMovie; + SE2::MuteChannelGroup("MUSIC", mute); + + if (mute) { + SI2::StopAllMusic(); + SI2::StopAIMusic(); + SI2::StopLuaMusic(); + } + } + + return true; +} + +// VERIFY: 7b1b9794 auto +// OFFSET: 0x004D1600 +void SI2::RegisterCVars() { + CVar::Register("ChatMusicVolume", "music volume (0.0 to 1.0)", 0, "0.3", nullptr, 7, false, nullptr, false); + CVar::Register("ChatSoundVolume", "sound volume (0.0 to 1.0)", 0, "0.4", nullptr, 7, false, nullptr, false); + CVar::Register("ChatAmbienceVolume", "Ambience Volume (0.0 to 1.0)", 0, "0.3", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableSFX", "", 0, "1", EnableSFXHandler, 7, false, nullptr, false); + CVar::Register("Sound_EnableAmbience", "Enable Ambience", 0, "1", EnableAmbienceHandler, 7, false, nullptr, false); + CVar::Register("Sound_EnableErrorSpeech", "error speech", 0, "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableMusic", "Enables music", 0, "1", EnableMusicHandler, 7, false, nullptr, false); + CVar::Register("Sound_EnableAllSound", "", 0, "1", EnableAllSoundHandler, 7, false, nullptr, false); + CVar::Register("Sound_MasterVolume", "master volume (0.0 to 1.0)", 0, "1.0", MasterVolumeHandler, 7, false, nullptr, false); + CVar::Register("Sound_SFXVolume", "sound volume (0.0 to 1.0)", 0, "1.0", SFXVolumeHandler, 7, false, nullptr, false); + CVar::Register("Sound_MusicVolume", "music volume (0.0 to 1.0)", 0, "0.4", MusicVolumeHandler, 7, false, nullptr, false); + CVar::Register("Sound_AmbienceVolume", "Ambience Volume (0.0 to 1.0)", 0, "0.6", AmbienceVolumeHandler, 7, false, nullptr, false); + CVar::Register("Sound_ListenerAtCharacter", "lock listener at character", 0, "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableEmoteSounds", "", 0, "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_ZoneMusicNoDelay", "", 0, "0", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableArmorFoleySoundForSelf", "", 0, "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableArmorFoleySoundForOthers", "", 0, "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableDSPEffects", "", 0, OsGetNumberOfProcessors() <= 1 ? "0" : "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnablePetSounds", "Enables pet sounds", 0, "1", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_EnableSoundWhenGameIsInBG", "Enable Sound When Game Is In Background", 0, "0", nullptr, 7, false, nullptr, false); + + if (CmdLineGetBool(static_cast(27))) { + CVar::Register("Sound_ChaosMode", "Testing to break sound engine", 0, "0", ChaosModeHandler, 7, false, nullptr, false); + CVar::Lookup("Sound_ChaosMode")->Set("0", true, false, false, true); + } + + CVar::Register("Sound_MaxCacheSizeInBytes", "Max cache size in bytes", 0, "16777216", nullptr, 7, false, nullptr, false); + CVar::Register("Sound_MaxCacheableSizeInBytes", "Max sound size that will be cached, larger files will be streamed instead", 0, "1048576", nullptr, 7, false, nullptr, false); + + static CVar* s_enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + static CVar* s_enableSFX = CVar::Lookup("Sound_EnableSFX"); + static CVar* s_enableErrorSpeech = CVar::Lookup("Sound_EnableErrorSpeech"); + static CVar* s_enableEmoteSounds = CVar::Lookup("Sound_EnableEmoteSounds"); + static CVar* s_enableMusic = CVar::Lookup("Sound_EnableMusic"); + static CVar* s_zoneMusicNoDelay = CVar::Lookup("Sound_ZoneMusicNoDelay"); + static CVar* s_enableAmbience = CVar::Lookup("Sound_EnableAmbience"); + static CVar* s_listenerAtCharacter = CVar::Lookup("Sound_ListenerAtCharacter"); + static CVar* s_enableSoundWhenGameIsInBG = CVar::Lookup("Sound_EnableSoundWhenGameIsInBG"); + static CVar* s_enableReverb = CVar::Lookup("Sound_EnableReverb"); + static CVar* s_enableSoftwareHRTF = CVar::Lookup("Sound_EnableSoftwareHRTF"); + static CVar* s_outputQuality = CVar::Lookup("Sound_OutputQuality"); + static CVar* s_numChannels = CVar::Lookup("Sound_NumChannels"); + static CVar* s_enableHardware = CVar::Lookup("Sound_EnableHardware"); + static CVar* s_masterVolume = CVar::Lookup("Sound_MasterVolume"); + static CVar* s_sfxVolume = CVar::Lookup("Sound_SFXVolume"); + static CVar* s_musicVolume = CVar::Lookup("Sound_MusicVolume"); + static CVar* s_ambienceVolume = CVar::Lookup("Sound_AmbienceVolume"); + static CVar* s_enableMixMode2 = CVar::Lookup("Sound_EnableMixMode2"); + static CVar* s_armorFoleySelf = CVar::Lookup("Sound_EnableArmorFoleySoundForSelf"); + static CVar* s_armorFoleyOthers = CVar::Lookup("Sound_EnableArmorFoleySoundForOthers"); + static CVar* s_dspBufferSize = CVar::Lookup("Sound_DSPBufferSize"); + + SE2::Log_Write("=> User Settings Report:"); + SE2::Log_Write(" - ========= PLAYBACK ========="); + SE2::Log_Write(" - Enable All Sound [%d]", s_enableAllSound->m_intValue); + SE2::Log_Write(" - Enable SFX [%d]", s_enableSFX->m_intValue); + SE2::Log_Write(" --- Enable Error Speech [%d]", s_enableErrorSpeech->m_intValue); + SE2::Log_Write(" --- Enable Emote Sounds [%d]", s_enableEmoteSounds->m_intValue); + SE2::Log_Write(" - Enable Music [%d]", s_enableMusic->m_intValue); + SE2::Log_Write(" --- Loop Music [%d]", s_zoneMusicNoDelay->m_intValue); + SE2::Log_Write(" - Enable Ambient Sounds [%d]", s_enableAmbience->m_intValue); + SE2::Log_Write(" - Sound at Character [%d]", s_listenerAtCharacter->m_intValue); + SE2::Log_Write(" - Sound in Background [%d]", s_enableSoundWhenGameIsInBG->m_intValue); + SE2::Log_Write(" - Enable Reverb [%d]", s_enableReverb->m_intValue); + SE2::Log_Write(" - Enable Software HRTF [%d]", s_enableSoftwareHRTF->m_intValue); + SE2::Log_Write(" - Sound Quality [%d]", s_outputQuality->m_intValue); + SE2::Log_Write(" -"); + SE2::Log_Write(" - ========== VOLUME =========="); + SE2::Log_Write(" - Master Volume [%.2f]", s_masterVolume->m_floatValue); + SE2::Log_Write(" - SFX Volume [%.2f]", s_sfxVolume->m_floatValue); + SE2::Log_Write(" - Music Volume [%.2f]", s_musicVolume->m_floatValue); + SE2::Log_Write(" - Ambience Volume [%.2f]", s_ambienceVolume->m_floatValue); + SE2::Log_Write(" -"); + SE2::Log_Write(" - =========== MISC ==========="); + SE2::Log_Write(" - Sound Channels [%d]", s_numChannels->m_intValue); + SE2::Log_Write(" - Use Hardware [%d]", s_enableHardware->m_intValue); + SE2::Log_Write(" - Mix Mode 2 [%d]", s_enableMixMode2->m_intValue); + + if (s_dspBufferSize->m_intValue) { + SE2::Log_Write(" - DSP Buffer Size [%d]", s_enableAmbience->m_intValue); + } else { + SE2::Log_Write(" - DSP Buffer Size [AUTO]"); + } + + SE2::Log_Write(" - Armor Foley SFX (Self) [%d]", s_armorFoleySelf->m_intValue); + SE2::Log_Write(" - Armor Foley SFX (Others) [%d]", s_armorFoleyOthers->m_intValue); + SE2::Log_Write("=> End of User Settings Report"); +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Combat.cpp b/WoW/Source/SoundInterface/SoundInterface2Combat.cpp new file mode 100644 index 0000000..062195a --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Combat.cpp @@ -0,0 +1,214 @@ +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2Combat.h" +#include "Engine/Source/Storm/H/stpl.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Object/ObjectClient/Item_C.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +// STATIC: 0x00B4AE7C +static TSFixedArray s_impactSounds; + +// STATIC: 0x00B4AE88 +static int32_t s_swingSounds[3][2]; + +// VERIFY: 647f0380 auto +// OFFSET: 0x007DA1F0 +IMPACTSOUND::IMPACTSOUND() { + this->m_soundId = 0; + this->m_critSoundId = 0; +} + +// VERIFY: 2250fb03 manual +// OFFSET: 0x004D0380 +static void InitWeaponImpactSound(WeaponImpactSoundsRec* rec) { + if (!s_impactSounds.m_count) { + return; + } + + IMPACTSOUNDARRAY* sounds = &s_impactSounds.m_data[rec->m_weaponSubClassID]; + + for (int32_t i = 0; i < 10; i++) { + sounds->m_sounds[i][rec->m_parrySoundType].m_soundId = rec->m_impactSoundID[i]; + sounds->m_sounds[i][rec->m_parrySoundType].m_critSoundId = rec->m_critImpactSoundID[i]; + } +} + +// VERIFY: d720637a auto +// OFFSET: 0x004D04E0 +void SI2::InitWeaponSwingCombatSounds() { + for (int32_t i = g_weaponSwingSounds2DB.m_numRecords; i;) { + i--; + + WeaponSwingSounds2Rec* rec = (i < 0 || i >= g_weaponSwingSounds2DB.m_numRecords) ? nullptr : &g_weaponSwingSounds2DB.m_records[i]; + + if (rec && rec->m_swingType < 3 && rec->m_crit < 2) { + s_swingSounds[rec->m_swingType][rec->m_crit != 0] = rec->m_soundID; + } + } +} + +// VERIFY: df290633 manual +// OFFSET: 0x004D0540 +void SI2::PlayParrySound(const CGUnitVirtualItem* weapon, const CGUnitVirtualItem* defender, int32_t crit, const C3Vector* position, int32_t self) { + if (!s_impactSounds.m_count) { + return; + } + + int32_t subclass; + int32_t metal; + + if (weapon) { + subclass = weapon->m_soundOverrideSubclassID; + + if (subclass == 0xFF) { + subclass = weapon->m_subclassID; + } + + metal = CGItem_C::IsMetal(weapon->m_material); + } else { + metal = 0; + subclass = ClientDBGetUnarmedWeapon(); + } + + int32_t type = 6; + + if (defender) { + if (defender->m_classID == 2) { + type = 6 - CGItem_C::IsMetal(defender->m_material); + } else if (defender->m_classID == 4) { + type = 4 - CGItem_C::IsMetal(defender->m_material); + } + } + + IMPACTSOUND* sound = &s_impactSounds.m_data[subclass].m_sounds[type][metal]; + + C3Vector soundPosition; + soundPosition.x = position->x; + soundPosition.y = position->y; + soundPosition.z = position->z + 2.0f; + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_group = 14; + + if (self) { + properties.m_priority = 110; + } + + SI2::PlaySoundKit(crit != 0 ? sound->m_critSoundId : sound->m_soundId, &soundPosition, nullptr, &properties, 0, nullptr, 1, 0); +} + +// VERIFY: 4ec94dcc manual +// OFFSET: 0x004D0660 +void SI2::PlayHitSound(const CGUnitVirtualItem* weapon, int32_t impactType, int32_t crit, const C3Vector* position, int32_t self) { + if (!s_impactSounds.m_count) { + return; + } + + int32_t subclass; + int32_t metal; + + if (weapon) { + subclass = weapon->m_soundOverrideSubclassID; + + if (subclass == 0xFF) { + subclass = weapon->m_subclassID; + } + + metal = CGItem_C::IsMetal(weapon->m_material); + } else { + metal = 0; + subclass = ClientDBGetUnarmedWeapon(); + } + + IMPACTSOUND* sound = &s_impactSounds.m_data[subclass].m_sounds[impactType][metal]; + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_group = 14; + + if (self) { + properties.m_priority = 110; + } + + SI2::PlaySoundKit(crit != 0 ? sound->m_critSoundId : sound->m_soundId, position, nullptr, &properties, 0, nullptr, 1, 0); +} + +// VERIFY: 1275dcb8 manual +// OFFSET: 0x004D0720 +int32_t SI2::PlayWeaponSwooshSound(int32_t type, int32_t crit, const C3Vector* position, int32_t quiet, int32_t self) { + if (type >= 3) { + return 0; + } + + float volume = quiet ? 0.5f : 1.0f; + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_volume = volume; + properties.m_group = 10; + + if (self) { + properties.m_priority = 110; + } + + return SI2::PlaySoundKit(s_swingSounds[type][crit != 0], position, nullptr, &properties, 0, nullptr, 1, 0); +} + +// VERIFY: 4281e82d manual +// OFFSET: 0x004D07B0 +int32_t SI2::PlaySheatheSound(const CGUnitVirtualItem* item, int32_t sheathe, const C3Vector* position, int32_t self) { + if (!item) { + return 0; + } + + MaterialRec* material = g_materialDB.GetRecord(item->m_material); + + if (!material) { + return 0; + } + + C3Vector soundPosition; + soundPosition.x = position->x; + soundPosition.y = position->y; + soundPosition.z = position->z + 2.0f; + + int32_t soundKitId = sheathe ? material->m_sheatheSoundID : material->m_unsheatheSoundID; + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + + if (self) { + properties.m_priority = 110; + } + + return SI2::PlaySoundKit(soundKitId, &soundPosition, nullptr, &properties, 0, nullptr, 1, 0); +} + +// VERIFY: c557bfee auto +// OFFSET: 0x004D0850 +int32_t SI2::PlayMissedSound(bool oneHand, const C3Vector* position, int32_t self) { + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + + if (self) { + properties.m_priority = 110; + } + + return SI2::PlaySoundKit(oneHand ? "(DONOTRENAME)Combat Miss 1H" : "(DONOTRENAME)Combat Miss 2H", position, nullptr, &properties); +} + +// VERIFY: 3aee2ee4 manual +// OFFSET: 0x004D0B70 +void SI2::InitWeaponImpactCombatSounds() { + s_impactSounds.SetCount(ClientDBGetNumWeaponSubClasses()); + + for (int32_t i = g_weaponImpactSoundsDB.m_numRecords; i;) { + i--; + + WeaponImpactSoundsRec* rec = (i < 0 || i >= g_weaponImpactSoundsDB.m_numRecords) ? nullptr : &g_weaponImpactSoundsDB.m_records[i]; + InitWeaponImpactSound(rec); + } +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Combat.h b/WoW/Source/SoundInterface/SoundInterface2Combat.h new file mode 100644 index 0000000..b71d4eb --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Combat.h @@ -0,0 +1,18 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2COMBAT_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2COMBAT_H + +#include +#include + +struct IMPACTSOUND { + /* 0000 */ int32_t m_soundId; + /* 0004 */ int32_t m_critSoundId; + + IMPACTSOUND(); +}; + +struct IMPACTSOUNDARRAY { + /* 0000 */ IMPACTSOUND m_sounds[10][2]; +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2DSP.cpp b/WoW/Source/SoundInterface/SoundInterface2DSP.cpp new file mode 100644 index 0000000..25c568d --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2DSP.cpp @@ -0,0 +1,215 @@ +#include +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2DSP.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/SoundEngine/SoundEngine.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +// STATIC: 0x00B4ADB4 +static TSHashTable s_dspChains; + +// VERIFY: 4b244940 auto +// OFFSET: 0x004CD9D0 +static FMOD_DSP_TYPE TranslateDspType(int32_t type) { + switch (type) { + case SI2_DSP_TYPE_PITCHSHIFT: + return FMOD_DSP_TYPE_PITCHSHIFT; + + case SI2_DSP_TYPE_HIGHPASS: + return FMOD_DSP_TYPE_HIGHPASS; + + case SI2_DSP_TYPE_LOWPASS: + return FMOD_DSP_TYPE_LOWPASS; + + case SI2_DSP_TYPE_CHORUS: + return FMOD_DSP_TYPE_CHORUS; + + case SI2_DSP_TYPE_ECHO: + return FMOD_DSP_TYPE_ECHO; + + default: + return FMOD_DSP_TYPE_UNKNOWN; + } +} + +// INLINED +SI2DspNode::SI2DspNode() { + this->m_dsp = nullptr; + this->m_type = -1; +} + +// INLINED +SI2DspChainHead::SI2DspChainHead() { + this->m_expireTime = 0.1f; +} + +// VERIFY: 3a7e7c8c manual +// OFFSET: 0x004CDC80 +void SI2::DSP_MakeDSPsExpire(float elapsed) { + for (DSP_CHAIN_HEAD_LOOKUP* head = s_dspChains.m_fulllist.Head(); head; head = s_dspChains.m_fulllist.Next(head)) { + if (SE2::GetChannelGroupNumChannels(head->m_chain.m_channelGroup)) { + continue; + } + + if (head->m_chain.m_expireTime > 0.0f && head->m_chain.m_expireTime - elapsed <= 0.0f) { + for (SI2DspNode* node = head->m_chain.m_nodes.Head(); node; node = head->m_chain.m_nodes.Next(node)) { + SE2::EnableDSP(node->m_dsp, false); + } + } + + head->m_chain.m_expireTime -= elapsed; + + if (head->m_chain.m_expireTime < 0.0f) { + head->m_chain.m_expireTime = 0.0f; + } + } +} + +// VERIFY: 427289d5 manual +// OFFSET: 0x004CDD40 +void SI2::DSP_ShutDown() { + for (DSP_CHAIN_HEAD_LOOKUP* head = s_dspChains.m_fulllist.Head(); head; head = s_dspChains.m_fulllist.Next(head)) { + for (SI2DspNode* node = head->m_chain.m_nodes.Head(); node; node = head->m_chain.m_nodes.Next(node)) { + SE2::DspDestroy(node->m_dsp); + node->m_dsp = nullptr; + } + + head->m_chain.m_nodes.Clear(); + + if (head->m_chain.m_channelGroup) { + SE2::DestroyChannelGroup(head->m_chain.m_channelGroup); + head->m_chain.m_channelGroup = nullptr; + } + } + + s_dspChains.Clear(); +} + +// VERIFY: 015e69f4 manual +// OFFSET: 0x004CDF70 +void SI2::DSP_CreateDsp(const char* name, int32_t type, const float* params) { + static CVar* s_enableDSPEffects = CVar::Lookup("Sound_EnableDSPEffects"); + + if (!s_enableDSPEffects->m_intValue) { + return; + } + + SI2DspNode* node = new (SMemAlloc(sizeof(SI2DspNode), __FILE__, __LINE__, 0)) SI2DspNode(); + + if (type != SI2_DSP_TYPE_VOLUME && SE2::CreateDSPByType(TranslateDspType(type), &node->m_dsp)) { + if (node) { + delete node; + } + + return; + } + + DSP_CHAIN_HEAD_LOOKUP* head = s_dspChains.Ptr(name); + head->m_chain.m_nodes.LinkToTail(node); + node->m_type = type; + + switch (type) { + case SI2_DSP_TYPE_PITCHSHIFT: + SE2::SetDspParam(node->m_dsp, 0, params[1]); + SE2::SetDspParam(node->m_dsp, 1, 512.0f); + break; + + case SI2_DSP_TYPE_HIGHPASS: + case SI2_DSP_TYPE_LOWPASS: + SE2::SetDspParam(node->m_dsp, 0, params[1]); + SE2::SetDspParam(node->m_dsp, 1, params[2]); + break; + + case SI2_DSP_TYPE_CHORUS: + SE2::SetDspParam(node->m_dsp, 0, params[1]); + SE2::SetDspParam(node->m_dsp, 1, params[2]); + SE2::SetDspParam(node->m_dsp, 2, params[3]); + SE2::SetDspParam(node->m_dsp, 3, params[4]); + SE2::SetDspParam(node->m_dsp, 4, params[5]); + SE2::SetDspParam(node->m_dsp, 5, params[6]); + SE2::SetDspParam(node->m_dsp, 6, params[7]); + SE2::SetDspParam(node->m_dsp, 7, params[8]); + break; + + case SI2_DSP_TYPE_ECHO: + SE2::SetDspParam(node->m_dsp, 0, params[1]); + SE2::SetDspParam(node->m_dsp, 1, params[2]); + SE2::SetDspParam(node->m_dsp, 3, params[3]); + SE2::SetDspParam(node->m_dsp, 4, params[4]); + break; + + case SI2_DSP_TYPE_VOLUME: + if (params[0] > 0.0f) { + SE2::SetFMODChannelGroupVolume(head->m_chain.m_channelGroup, params[1]); + } + + break; + + default: + break; + } + + if (type != SI2_DSP_TYPE_VOLUME) { + SE2::BypassDsp(node->m_dsp, 0.0f == params[0]); + SE2::ConnectDspToChannelGroup(node->m_dsp, head->m_chain.m_channelGroup); + } +} + +// VERIFY: e4c6f172 manual +// OFFSET: 0x004CE250 +void SI2::DSP_AttachCustomDspChain(FMOD::Channel* channel, char* name) { + DSP_CHAIN_HEAD_LOOKUP* head = s_dspChains.Ptr(name); + + if (!head) { + return; + } + + for (SI2DspNode* node = head->m_chain.m_nodes.Head(); node; node = head->m_chain.m_nodes.Next(node)) { + SE2::EnableDSP(node->m_dsp, true); + } + + head->m_chain.m_expireTime = 3.0f; + SE2::AddChannelToChannelGroup(channel, head->m_chain.m_channelGroup); +} + +// VERIFY: 1f3d2404 manual +// OFFSET: 0x004CE7C0 +void SI2::DSP_Init() { + for (int32_t i = 0; i < g_soundFilterDB.m_numRecords; i++) { + SoundFilterRec* rec = (i < 0 || i >= g_soundFilterDB.m_numRecords) ? nullptr : &g_soundFilterDB.m_records[i]; + + if (s_dspChains.Ptr(rec->m_name)) { + continue; + } + + const char* name = rec->m_name; + DSP_CHAIN_HEAD_LOOKUP* head = s_dspChains.New(name, 0, 0); + + for (SI2DspNode* node = head->m_chain.m_nodes.Head(); node; node = head->m_chain.m_nodes.Next(node)) { + SE2::DspDestroy(node->m_dsp); + node->m_dsp = nullptr; + } + + head->m_chain.m_nodes.Clear(); + + if (!head->m_chain.m_channelGroup) { + head->m_chain.m_channelGroup = SE2::CreateChannelGroup(rec->m_name); + } + } + + for (int32_t i = 0; i < g_soundFilterElemDB.m_numRecords; i++) { + SoundFilterElemRec* elem = (i < 0 || i >= g_soundFilterElemDB.m_numRecords) ? nullptr : &g_soundFilterElemDB.m_records[i]; + SoundFilterRec* filter = g_soundFilterDB.GetRecord(elem->m_soundFilterID); + + SI2::DSP_CreateDsp(filter->m_name, elem->m_filterType, elem->m_params); + } + + for (DSP_CHAIN_HEAD_LOOKUP* head = s_dspChains.m_fulllist.Head(); head; head = s_dspChains.m_fulllist.Next(head)) { + for (SI2DspNode* node = head->m_chain.m_nodes.Head(); node; node = head->m_chain.m_nodes.Next(node)) { + SE2::EnableDSP(node->m_dsp, false); + } + } +} diff --git a/WoW/Source/SoundInterface/SoundInterface2DSP.h b/WoW/Source/SoundInterface/SoundInterface2DSP.h new file mode 100644 index 0000000..2b07173 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2DSP.h @@ -0,0 +1,31 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2DSP_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2DSP_H + +#include +#include +#include "Engine/Source/SoundEngine/fmodex/src/fmod.hpp" +#include "Engine/Source/Storm/H/stpl.h" +#include "WoW/Source/SoundInterface/Types.h" + +class SI2DspNode : public TSLinkedNode { + public: + /* 0008 */ FMOD::DSP* m_dsp; + /* 000C */ int32_t m_type; + + SI2DspNode(); +}; + +class SI2DspChainHead { + public: + /* 0000 */ TSList > m_nodes; + /* 000C */ FMOD::ChannelGroup* m_channelGroup; + /* 0010 */ float m_expireTime; + + SI2DspChainHead(); +}; + +struct DSP_CHAIN_HEAD_LOOKUP : public TSHashObject { + /* 0018 */ SI2DspChainHead m_chain; +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2Emotes.cpp b/WoW/Source/SoundInterface/SoundInterface2Emotes.cpp new file mode 100644 index 0000000..83617af --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Emotes.cpp @@ -0,0 +1,110 @@ +#include +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2Emotes.h" +#include "Engine/Source/Storm/H/stpl.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/SoundInterface/SoundInterface2Internal.h" + +// STATIC: 0x00B4ADE4 +static TSGrowableArray s_textEmoteLookups; + +// STATIC: 0x00B4ADF0 +static int32_t s_numTextEmotes; + +// STATIC: 0x00B4ADF4 +static TSGrowableArray s_textEmoteLookupById; + +// INLINED +TEXTEMOTELOOKUP::TEXTEMOTELOOKUP() { + this->m_emotesTextId = 0; + memset(this->m_soundIds, 0, sizeof(this->m_soundIds)); +} + +// VERIFY: b8c12fce auto +// OFFSET: 0x004CEB30 +int32_t SI2::GetTextEmoteSoundID(uint32_t emotesTextId, uint32_t race, uint32_t sex) { + TEXTEMOTELOOKUP* lookup; + + if (emotesTextId < s_textEmoteLookupById.Count() && (lookup = s_textEmoteLookupById[emotesTextId]) != nullptr && race < 22 && sex < 2) { + return lookup->m_soundIds[race][sex]; + } + + return 0; +} + +// VERIFY: 8c9fb06d auto +// OFFSET: 0x004CEB70 +int32_t SI2::GetTextEmoteSoundIndex(uint32_t emotesTextId, uint32_t race, uint32_t sex) { + TEXTEMOTELOOKUP* lookup; + int32_t soundKitId; + + if (emotesTextId < s_textEmoteLookupById.Count() && (lookup = s_textEmoteLookupById[emotesTextId]) != nullptr && race < 22 && sex < 2) { + soundKitId = lookup->m_soundIds[race][sex]; + } else { + soundKitId = 0; + } + + VSOUNDKITDEF* def = SI2::GetSoundKitDef(soundKitId); + + if (!def || !def->m_numFiles) { + return -1; + } + + int32_t index = 0; + def->SelectFile(2, &index, -1, 5); + return index; +} + +// VERIFY: bf97a618 auto +// OFFSET: 0x004CECB0 +void SI2::InitEmoteSounds() { + if (!g_emotesTextDB.m_numRecords || !g_emotesTextSoundDB.m_numRecords) { + return; + } + + s_textEmoteLookupById.SetCount(g_emotesTextDB.m_maxID + 1); + memset(s_textEmoteLookupById.Ptr(), 0, sizeof(TEXTEMOTELOOKUP*) * s_textEmoteLookupById.Count()); + + int32_t last = -1; + int32_t count = 0; + + for (int32_t i = 0; i < g_emotesTextSoundDB.m_numRecords; i++) { + EmotesTextSoundRec* rec = (i < 0 || i >= g_emotesTextSoundDB.m_numRecords) ? nullptr : &g_emotesTextSoundDB.m_records[i]; + + if (last == -1 || last != rec->m_emotesTextID) { + last = rec->m_emotesTextID; + count++; + } + } + + s_numTextEmotes = count; + + for (int32_t i = 0; i < g_emotesTextSoundDB.m_numRecords; i++) { + EmotesTextSoundRec* rec = (i < 0 || i >= g_emotesTextSoundDB.m_numRecords) ? nullptr : &g_emotesTextSoundDB.m_records[i]; + uint32_t id = rec->m_emotesTextID; + + if (id >= s_textEmoteLookupById.Count()) { + continue; + } + + TEXTEMOTELOOKUP** slot = &s_textEmoteLookupById[id]; + + if (!*slot) { + *slot = s_textEmoteLookups.New(); + (*slot)->m_emotesTextId = rec->m_emotesTextID; + } + + if (static_cast(rec->m_raceID) < 22 && static_cast(rec->m_sexID) < 2) { + (*slot)->m_soundIds[rec->m_raceID][rec->m_sexID] = rec->m_soundID; + } + } +} + +// VERIFY: cf5849ee manual +// OFFSET: 0x004CEDF0 +void SI2::FreeEmoteSounds() { + s_textEmoteLookups.Clear(); + s_textEmoteLookupById.Clear(); +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Emotes.h b/WoW/Source/SoundInterface/SoundInterface2Emotes.h new file mode 100644 index 0000000..3bcbb42 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Emotes.h @@ -0,0 +1,14 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2EMOTES_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2EMOTES_H + +#include +#include + +struct TEXTEMOTELOOKUP { + /* 0000 */ int32_t m_soundIds[22][2]; + /* 00B0 */ int32_t m_emotesTextId; + + TEXTEMOTELOOKUP(); +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2Foley.cpp b/WoW/Source/SoundInterface/SoundInterface2Foley.cpp new file mode 100644 index 0000000..0d98bfc --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Foley.cpp @@ -0,0 +1,119 @@ +#include +#include +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/SoundEngine/SoundEngine.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/Ui/ChatFrame.h" + +// STATIC: 0x00B4AE40 +int32_t CGChat::m_paused; + +// VERIFY: 88e41fa1 auto +// OFFSET: 0x004CFB50 +void SI2::SetPitch(SE2SoundKitObject* object, float pitch) { + object->m_sound.SetPitch(pitch); +} + +// VERIFY: f573d0ba auto +// OFFSET: 0x004CFB70 +void SI2::Detach(SE2SoundKitObject* object) { + object->m_sound.Detach(); +} + +// VERIFY: f6cf06fb auto +// OFFSET: 0x004CFB80 +void CGChat::LeaveWorld() { + CGChat::m_paused++; +} + +// VERIFY: 62ef2d2f auto +// OFFSET: 0x004CFB90 +void CGChat::Resume() { + CGChat::m_paused--; +} + +// VERIFY: 7732767c auto +// OFFSET: 0x004CFBA0 +int32_t CGChat::IsPaused() { + return CGChat::m_paused; +} + +// VERIFY: f4fa7734 manual +// OFFSET: 0x004CFC10 +int32_t SI2::PlayFoleySound(int32_t materialId, const C3Vector* position, int32_t self) { + MaterialRec* material = g_materialDB.GetRecord(materialId); + + if (!material || !material->m_foleySoundID) { + return 0; + } + + C3Vector soundPosition; + soundPosition.x = position->x; + soundPosition.y = position->y; + soundPosition.z = position->z + 2.0f; + + if (!self) { + return SI2::PlaySoundKit(material->m_foleySoundID, &soundPosition, nullptr, nullptr, 0, nullptr, 1, 0); + } + + static CVar* s_listenerAtCharacter = CVar::Lookup("Sound_ListenerAtCharacter"); + + int32_t listenerAtCharacter = s_listenerAtCharacter->m_intValue; + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + + if (listenerAtCharacter) { + properties.m_volumeScale = 0.65f; + } + + properties.m_priority = 110; + + return SI2::PlaySoundKit(material->m_foleySoundID, listenerAtCharacter == 0 ? &soundPosition : nullptr, nullptr, &properties, 0, nullptr, 1, 0); +} + +// VERIFY: 9dd45739 manual +// OFFSET: 0x004CFE00 +int32_t SI2::IsTooCloseToExistingSoundKit(int32_t soundKitId, const C3Vector* position) { + SEChannelInfo info[512]; + uint32_t hardwareCount; + uint32_t softwareCount; + uint32_t virtualCount; + uint32_t loadingCount; + uint32_t otherCount; + + int32_t count = SE2::GetChannelInfo(info, 512, 1, 1, 0, 0, &hardwareCount, &softwareCount, &virtualCount, &loadingCount, &otherCount); + + for (int32_t i = 0; i < count; i++) { + SI2SoundUserData* userData = static_cast(info[i].m_userData); + + if (userData && userData->m_soundKitId == soundKitId) { + float dx = position->x - info[i].m_position.x; + float dy = position->y - info[i].m_position.y; + float dz = position->z - info[i].m_position.z; + + if (dx * dx + dz * dz + dy * dy < 6.0f) { + return 1; + } + } + } + + return 0; +} + +// VERIFY: fc148494 manual +// OFFSET: 0x004D0090 +void SI2::PlayItemSound(int32_t type, int32_t displayId) { + ItemDisplayInfoRec display; + + if (!g_itemDisplayInfoDB.GetRecord(displayId, &display)) { + return; + } + + ItemGroupSoundsRec* sounds = g_itemGroupSoundsDB.GetRecord(display.m_groupSoundIndex); + + if (sounds) { + SI2::PlaySoundKit(sounds->m_sound[type], nullptr, nullptr, nullptr, 0, nullptr, 1, 0); + } +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Footsteps.cpp b/WoW/Source/SoundInterface/SoundInterface2Footsteps.cpp new file mode 100644 index 0000000..e4ad8b1 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Footsteps.cpp @@ -0,0 +1,135 @@ +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2Footsteps.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +// STATIC: 0x00B4AE04 +static HASHKEY_NONE s_footstepKey; + +// STATIC: 0x00B4AE10 +static TSHashTable s_footstepSounds; + +// VERIFY: 3cde8edb auto +// OFFSET: 0x004CEE50 +bool CGUnit_C::IsActivePlayer() { + return (static_cast(this->m_obj->m_guid.m_guidHigh) << 32 | this->m_obj->m_guid.m_guidLow) == ClntObjMgrGetActivePlayer(); +} + +// VERIFY: 1432f0e0 manual +// OFFSET: 0x004CF060 +void SI2::FreeFootstepSounds() { + s_footstepSounds.Clear(); +} + +// VERIFY: 8151ef99 manual +// OFFSET: 0x004CF100 +static uint32_t GetFootstepSound(int32_t terrainType, int32_t footstepId, int32_t splash) { + TerrainTypeRec* terrain = g_terrainTypeDB.GetRecord(terrainType); + + if (!terrain) { + return 0; + } + + int32_t index = terrain->m_soundID; + FOOTSTEPSNDCACHE* cache = s_footstepSounds.Ptr(footstepId, s_footstepKey); + + if (!cache) { + return 0; + } + + if (splash) { + return cache->m_splashSounds[index]; + } + + return cache->m_sounds[index]; +} + +// VERIFY: 508a3422 manual +// OFFSET: 0x004CF170 +void SI2::PlayFootstepSound(int32_t footstepId, const C3Vector* position, int32_t terrainType, int32_t splash, int32_t loud, CGUnit_C* unit) { + if (!unit) { + return; + } + + static CVar* s_listenerAtCharacter = CVar::Lookup("Sound_ListenerAtCharacter"); + + if (!s_listenerAtCharacter) { + return; + } + + uint32_t soundKitId = GetFootstepSound(terrainType, footstepId, splash); + + if (!soundKitId) { + soundKitId = GetFootstepSound(0, footstepId, splash); + + if (!soundKitId) { + return; + } + } + + SE2SoundKitProperties properties; + + if ((unit->m_obj->m_type & TYPEMASK_PLAYER) && unit->IsActivePlayer() && s_listenerAtCharacter->m_intValue) { + properties.ResetToDefaults(); + properties.m_maxDistance = loud ? 50.0f : 20.0f; + properties.m_volumeScale = 0.65f; + properties.m_group = 17; + properties.m_priority = 115; + SI2::PlaySoundKit(soundKitId, nullptr, nullptr, &properties, 0, nullptr, 1, 0); + } else if ((unit->m_obj->m_type & TYPEMASK_PLAYER) && unit->IsActivePlayer()) { + properties.ResetToDefaults(); + properties.m_group = 17; + properties.m_priority = 115; + SI2::PlaySoundKit(soundKitId, position, nullptr, &properties, 0, nullptr, 1, 0); + } else { + properties.ResetToDefaults(); + properties.m_group = 13; + properties.m_maxAudibleBehavior = 0; + SI2::PlaySoundKit(soundKitId, position, nullptr, &properties, 0, nullptr, 1, 0); + } +} + +// VERIFY: 25b83170 auto +// OFFSET: 0x004CF490 +FOOTSTEPSNDCACHE::FOOTSTEPSNDCACHE() { + this->m_sounds.Clear(); + this->m_splashSounds.Clear(); +} + +// VERIFY: b9aab4ae manual +// OFFSET: 0x004CF990 +void SI2::InitFootstepSounds() { + s_footstepSounds.Clear(); + + uint32_t count = g_terrainTypeSoundsDB.m_maxID + 1; + + for (int32_t i = g_footstepTerrainLookupDB.m_numRecords; i;) { + i--; + + FootstepTerrainLookupRec* rec = (i < 0 || i >= g_footstepTerrainLookupDB.m_numRecords) ? nullptr : &g_footstepTerrainLookupDB.m_records[i]; + + if (!rec || rec->m_terrainSoundID < 0) { + continue; + } + + FOOTSTEPSNDCACHE* cache = s_footstepSounds.Ptr(rec->m_creatureFootstepID, s_footstepKey); + + if (!cache) { + cache = s_footstepSounds.New(rec->m_creatureFootstepID, s_footstepKey, 0, 0); + cache->m_sounds.SetCount(count); + cache->m_splashSounds.SetCount(count); + + for (uint32_t j = 0; j < count; j++) { + cache->m_sounds[j] = 0; + cache->m_splashSounds[j] = 0; + } + } + + cache->m_sounds[rec->m_terrainSoundID] = rec->m_soundID; + cache->m_splashSounds[rec->m_terrainSoundID] = rec->m_soundIdsplash; + } +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Footsteps.h b/WoW/Source/SoundInterface/SoundInterface2Footsteps.h new file mode 100644 index 0000000..dbd982d --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Footsteps.h @@ -0,0 +1,15 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2FOOTSTEPS_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2FOOTSTEPS_H + +#include +#include +#include "Engine/Source/Storm/H/stpl.h" + +struct FOOTSTEPSNDCACHE : public TSHashObject { + /* 0018 */ TSGrowableArray m_sounds; + /* 0028 */ TSGrowableArray m_splashSounds; + + FOOTSTEPSNDCACHE(); +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2Glue.cpp b/WoW/Source/SoundInterface/SoundInterface2Glue.cpp new file mode 100644 index 0000000..c38a2d8 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Glue.cpp @@ -0,0 +1,169 @@ +#include +#include +#include "Engine/Source/Event/Event.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/SoundInterface/SoundInterface2Internal.h" + +// STATIC: 0x00DCE8E8 +static char s_creditsMusicName[128]; + +// STATIC: 0x00DCE968 +static char s_glueMusicName[128]; + +// STATIC: 0x00DCE9E8 +static char s_glueAmbienceName[128]; + +// STATIC: 0x00DCEA68 +static SE2SoundKitObject s_creditsMusic; + +// STATIC: 0x00DCEA7C +static SE2SoundKitObject s_glueMusic; + +// STATIC: 0x00DCEA90 +static SE2SoundKitObject s_glueAmbience; + +// VERIFY: f19203b8 auto +// OFFSET: 0x00985F70 +void SI2::StopGlueAmbience(float fadeOutTime) { + if (fadeOutTime < 0.0f) { + fadeOutTime = -1.0f; + } + + SI2::StopSound(&s_glueAmbience, 0, fadeOutTime, 1); +} + +// VERIFY: 57028033 auto +// OFFSET: 0x00985FB0 +void SI2::StartGlueAmbience(const char* name, float fadeInTime) { + if (SI2::IsPlaying(&s_glueAmbience)) { + VSOUNDKITDEF* def = SI2::GetSoundKitDef(SI2::LookupSoundKitId(name)); + SI2SoundUserData* userData = static_cast(s_glueAmbience.m_sound.GetUserData()); + + if (def && userData && def->m_id == userData->m_soundKitId) { + return; + } + } + + SI2::StopSound(&s_glueAmbience, 0, 3.0f, 1); + + if (!name) { + return; + } + + SStrCopy(s_glueAmbienceName, name, sizeof(s_glueAmbienceName)); + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_fadeInTime = fadeInTime; + properties.m_group = 2; + properties.m_loopMode = 1; + properties.m_decodeBufferSize = 0; + + SI2::PlaySoundKit(s_glueAmbienceName, nullptr, &s_glueAmbience, &properties); +} + +// VERIFY: ba080d04 auto +// OFFSET: 0x00986080 +int32_t SI2::GlueMusicUpdate(const void* data, void* param) { + if (!SI2::IsPlaying(&s_glueMusic)) { + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_group = 1; + properties.m_decodeBufferSize = 0; + + SI2::PlaySoundKit(s_glueMusicName, nullptr, &s_glueMusic, &properties); + } + + return 1; +} + +// VERIFY: 6c059ee6 auto +// OFFSET: 0x009860E0 +void SI2::StopGlueMusic(float fadeOutTime) { + EventUnregister(EVENT_ID_POLL, SI2::GlueMusicUpdate); + s_glueMusicName[0] = '\0'; + + if (fadeOutTime < 0.0f) { + fadeOutTime = -1.0f; + } + + SI2::StopSound(&s_glueMusic, 0, fadeOutTime, 1); +} + +// VERIFY: 8d99a4e4 auto +// OFFSET: 0x00986130 +int32_t SI2::CreditsMusicUpdate(const void* data, void* param) { + if (!SI2::IsPlaying(&s_creditsMusic)) { + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_group = 1; + properties.m_selectMode = 0; + + SI2::PlaySoundKit(s_creditsMusicName, nullptr, &s_creditsMusic, &properties); + } + + return 1; +} + +// VERIFY: c72e61eb auto +// OFFSET: 0x00986190 +void SI2::StopCreditsMusic() { + EventUnregister(EVENT_ID_POLL, SI2::CreditsMusicUpdate); + SI2::StopSound(&s_creditsMusic, 0, 3.0f, 1); +} + +// VERIFY: b62c8d0a auto +// OFFSET: 0x009861C0 +void SI2::StartGlueMusic(const char* name) { + if (SI2::IsPlaying(&s_glueMusic)) { + VSOUNDKITDEF* def = SI2::GetSoundKitDef(SI2::LookupSoundKitId(name)); + SI2SoundUserData* userData = static_cast(s_glueMusic.m_sound.GetUserData()); + + if (def && userData && def->m_id == userData->m_soundKitId) { + return; + } + } + + EventUnregister(EVENT_ID_POLL, SI2::CreditsMusicUpdate); + SI2::StopSound(&s_creditsMusic, 0, 3.0f, 1); + + if (!name || !SStrCmpI(name, s_glueMusicName, 0x7FFFFFFF)) { + return; + } + + SI2::StopGlueMusic(-1.0f); + SStrCopy(s_glueMusicName, name, sizeof(s_glueMusicName)); + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_group = 1; + properties.m_decodeBufferSize = 0; + + SI2::PlaySoundKit(s_glueMusicName, nullptr, &s_glueMusic, &properties); + EventRegister(EVENT_ID_POLL, SI2::GlueMusicUpdate); +} + +// VERIFY: f023fa69 auto +// OFFSET: 0x009862C0 +void SI2::StartCreditsMusic(const char* name) { + EventUnregister(EVENT_ID_POLL, SI2::CreditsMusicUpdate); + SI2::StopSound(&s_creditsMusic, 0, 3.0f, 1); + EventUnregister(EVENT_ID_POLL, SI2::GlueMusicUpdate); + s_glueMusicName[0] = '\0'; + SI2::StopSound(&s_glueMusic, 0, 3.0f, 1); + + if (!name) { + return; + } + + SStrCopy(s_creditsMusicName, name, sizeof(s_creditsMusicName)); + SI2::ResetSoundKitVariants(s_creditsMusicName); + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + properties.m_selectMode = 0; + + SI2::PlaySoundKit(s_creditsMusicName, nullptr, &s_creditsMusic, &properties); + EventRegister(EVENT_ID_POLL, SI2::CreditsMusicUpdate); +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Internal.cpp b/WoW/Source/SoundInterface/SoundInterface2Internal.cpp new file mode 100644 index 0000000..f5654eb --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Internal.cpp @@ -0,0 +1,533 @@ +#include +#include +#include +#include +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2Internal.h" +#include "Engine/Source/BlizzardCore/SFile2-Core.h" +#include "Engine/Source/Storm/H/storm.h" +#include "Engine/Source/Tempest/CRandom.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/SoundInterface/SoundInterface2ZoneSounds.h" +#include "WoW/Source/Ui/CGWorldStateInfo.h" + +// STATIC: 0x00B4AD3C +static TSGrowableArray s_soundKitDefs; + +// STATIC: 0x00B4AD4C +static TSHashTable s_soundKitLookup; + +// STATIC: 0x00B4AD74 +static TSGrowableArray s_worldStateZoneSoundOverrides; + +// STATIC: 0x00B4AD84 +static TSHashTable s_zoneSoundOverrides; + +// VERIFY: 14413abb auto +// OFFSET: 0x004CB8C0 +VSOUNDKITDEF::~VSOUNDKITDEF() { + for (int32_t i = 0; i < 10; i++) { + if (this->m_files[i]) { + free(this->m_files[i]); + this->m_files[i] = nullptr; + } + } +} + +// VERIFY: cca97730 auto +// OFFSET: 0x004CB8F0 +void VSOUNDKITDEF::ResetWeights() { + for (int32_t i = 0; i < 10; i++) { + this->m_weights[i] = 0; + } +} + +// VERIFY: eb26f6c8 auto +// OFFSET: 0x004CBA50 +VSOUNDKITDEF::VSOUNDKITDEF() { + this->m_numFiles = 0; + this->m_advancedId = 0; + + for (int32_t i = 0; i < 10; i++) { + this->m_files[i] = nullptr; + } + + for (int32_t i = 0; i < 10; i++) { + this->m_weights[i] = 0; + } + + this->m_lastIndex = -1; + this->m_pendingIndex = -1; + this->m_downloadPending = 0; +} + +// VERIFY: 229de6de manual +// OFFSET: 0x004CBAC0 +const char* VSOUNDKITDEF::SelectFile(uint32_t mode, int32_t* index, int32_t fileIndex, int32_t priority) { + if (mode > 2) { + return nullptr; + } + + if (this->m_numFiles <= 0) { + return nullptr; + } + + if (this->m_downloadPending) { + if (this->m_lastIndex < 0) { + this->m_lastIndex = 0; + } + + return this->m_files[this->m_lastIndex]; + } + + if (fileIndex > -1) { + int32_t selected = this->m_numFiles - 1; + + if (fileIndex < selected) { + selected = fileIndex; + } + + this->m_lastIndex = selected; + + if (index) { + *index = selected; + } + + return this->m_files[selected]; + } + + if (this->m_numFiles == 1) { + this->m_lastIndex = 0; + + if (index) { + *index = 0; + } + + return this->m_files[0]; + } + + int32_t total; + + for (int32_t pass = 0;; pass++) { + total = 0; + + if (pass == 2) { + this->m_lastIndex = -1; + } else if (pass >= 3) { + return nullptr; + } + + for (int32_t i = 0; i < this->m_numFiles; i++) { + if (i != this->m_lastIndex) { + total += this->m_weights[i]; + } + } + + if (total) { + break; + } + + if (mode == 0) { + for (int32_t i = 0; i < 10; i++) { + this->m_weights[i] = 1; + } + } else if (mode == 1 || mode == 2) { + for (int32_t i = 0; i < this->m_numFiles; i++) { + this->m_weights[i] = this->m_frequencies[i]; + } + } else { + break; + } + } + + int32_t roll = mode ? static_cast((static_cast(static_cast(total)) * CRandom::uint32_(g_rndSeed)) >> 32) : 0; + + int32_t state = 1; + + if (this->m_pendingIndex >= 0) { + state = SFile::FileIsLocal(this->m_files[this->m_pendingIndex], priority); + + if (state && state != 2) { + this->m_pendingIndex = -1; + } + } + + int32_t selected = -1; + int32_t i; + + for (i = 0; i < this->m_numFiles; i++) { + if (i != this->m_lastIndex) { + roll -= this->m_weights[i]; + } + + if (roll < 0) { + break; + } + } + + if (i < this->m_numFiles) { + if (SFile::IsStreamingMode()) { + state = SFile::FileIsLocal(this->m_files[i], priority); + } + + if (state && state != 2) { + this->m_weights[i]--; + selected = i; + } else { + if (this->m_pendingIndex < 0) { + SFile::MakeFileLocal(this->m_files[i], priority, false); + this->m_pendingIndex = i; + } + + int32_t fallback = i; + + if (SFile::IsStreamingMode()) { + for (int32_t j = i - 1; j >= 0; j--) { + int32_t local = SFile::FileIsLocal(this->m_files[j], priority); + + if (local && local != 2) { + fallback = j; + break; + } + } + } + + selected = fallback; + } + } else { + selected = 0; + } + + if (mode == 1) { + for (int32_t k = 0; k < 10; k++) { + this->m_weights[k] = 0; + } + } + + this->m_lastIndex = selected; + + if (index) { + *index = selected; + } + + return this->m_files[selected]; +} + +// VERIFY: b9dea2b7 auto +// OFFSET: 0x004CBDB0 +void SI2::CreateSoundGroups() { + for (uint32_t i = 0; i < s_soundKitDefs.Count(); i++) { + VSOUNDKITDEF* def = s_soundKitDefs[i]; + + if (def && def->m_name) { + def->m_loadSoundGroup = SE2::CreateSoundGroup(def->m_name, 3); + def->m_soundGroup = SE2::CreateSoundGroup(def->m_name, 3); + } + } +} + +// VERIFY: c9a76bad manual +// OFFSET: 0x004CBE00 +void SI2::ReleaseSoundGroups() { + for (uint32_t i = 0; i < s_soundKitDefs.Count(); i++) { + VSOUNDKITDEF* def = s_soundKitDefs[i]; + + if (def) { + if (def->m_loadSoundGroup) { + SE2::ReleaseSoundGroup(def->m_loadSoundGroup); + def->m_loadSoundGroup = nullptr; + } + + if (def->m_soundGroup) { + SE2::ReleaseSoundGroup(def->m_soundGroup); + def->m_soundGroup = nullptr; + } + } + } +} + +// VERIFY: b21cd78a manual +// OFFSET: 0x004CBE70 +int32_t SI2::UpdateZoneSoundsForWorldState(int32_t areaId, int32_t zoneId, int32_t wmoAreaId, int32_t wmoGroupAreaId, int32_t inside) { + int32_t count = s_worldStateZoneSoundOverrides.Count(); + int32_t found = 0; + + if (inside) { + for (int32_t i = 0; i < count; i++) { + WorldStateZoneSoundOverride* entry = s_worldStateZoneSoundOverrides[i]; + + if ((wmoAreaId > 0 && wmoAreaId == entry->m_wmoAreaId) || (wmoGroupAreaId > 0 && wmoGroupAreaId == entry->m_wmoAreaId)) { + if (GetWorldState(entry->m_worldStateId) == entry->m_worldStateValue) { + SI2::SetZoneReverb(1, s_worldStateZoneSoundOverrides[i]->m_soundProviderPreferencesId); + SI2::SetZoneAmbienceID(1, s_worldStateZoneSoundOverrides[i]->m_soundAmbienceId); + SI2::SetZoneIntroMusicID(6, s_worldStateZoneSoundOverrides[i]->m_zoneIntroMusicId); + SI2::SetZoneMusicID(1, s_worldStateZoneSoundOverrides[i]->m_zoneMusicId); + found = 1; + + if (wmoGroupAreaId == s_worldStateZoneSoundOverrides[i]->m_wmoAreaId) { + return 1; + } + } + } + } + + if (found) { + return 1; + } + } else if (wmoAreaId > 0 || wmoGroupAreaId > 0) { + int32_t best = 4; + + for (int32_t i = 0; i < count; i++) { + WorldStateZoneSoundOverride* entry = s_worldStateZoneSoundOverrides[i]; + int32_t rank = 4; + + if (areaId > 0 && areaId == entry->m_areaId) { + rank = 3; + } + + if (zoneId > 0 && zoneId == entry->m_areaId) { + rank = 2; + } + + if (wmoGroupAreaId > 0 && wmoGroupAreaId == entry->m_wmoAreaId) { + rank = 0; + } + + if (rank < best && GetWorldState(entry->m_worldStateId) == entry->m_worldStateValue) { + SI2::SetZoneReverb(1, s_worldStateZoneSoundOverrides[i]->m_soundProviderPreferencesId); + SI2::SetZoneAmbienceID(1, s_worldStateZoneSoundOverrides[i]->m_soundAmbienceId); + SI2::SetZoneIntroMusicID(6, s_worldStateZoneSoundOverrides[i]->m_zoneIntroMusicId); + SI2::SetZoneMusicID(1, s_worldStateZoneSoundOverrides[i]->m_zoneMusicId); + found = 1; + best = rank; + + if (!rank) { + return 1; + } + } + } + + if (found) { + return 1; + } + } else { + for (int32_t i = 0; i < count; i++) { + WorldStateZoneSoundOverride* entry = s_worldStateZoneSoundOverrides[i]; + + if ((areaId > 0 && areaId == entry->m_areaId) || (zoneId > 0 && zoneId == entry->m_areaId)) { + if (GetWorldState(entry->m_worldStateId) == entry->m_worldStateValue) { + SI2::SetZoneReverb(1, s_worldStateZoneSoundOverrides[i]->m_soundProviderPreferencesId); + SI2::SetZoneAmbienceID(1, s_worldStateZoneSoundOverrides[i]->m_soundAmbienceId); + SI2::SetZoneIntroMusicID(6, s_worldStateZoneSoundOverrides[i]->m_zoneIntroMusicId); + SI2::SetZoneMusicID(1, s_worldStateZoneSoundOverrides[i]->m_zoneMusicId); + found = 1; + + if (zoneId == s_worldStateZoneSoundOverrides[i]->m_areaId) { + return 1; + } + } + } + } + + if (found) { + return 1; + } + } + + SI2::SetZoneReverb(1, -1); + SI2::SetZoneAmbienceID(1, -1); + SI2::SetZoneIntroMusicID(6, -1); + SI2::SetZoneMusicID(1, -1); + return 0; +} + +// VERIFY: 6f1b3998 auto +// OFFSET: 0x004CC180 +VSOUNDKITDEF* SI2::GetSoundKitDef(int32_t soundKitId) { + if (soundKitId >= static_cast(s_soundKitDefs.Count()) || soundKitId <= 0) { + return nullptr; + } + + return s_soundKitDefs[soundKitId]; +} + +// VERIFY: 76ad8733 manual +// OFFSET: 0x004CC1B0 +void SI2::InitWorldStateZoneSoundOverrides() { + uint32_t count = g_worldStateZoneSoundsDB.m_numRecords; + s_worldStateZoneSoundOverrides.SetCount(count); + memset(s_worldStateZoneSoundOverrides.Ptr(), 0, sizeof(WorldStateZoneSoundOverride*) * count); + + for (uint32_t i = 0; i < s_worldStateZoneSoundOverrides.Count(); i++) { + s_worldStateZoneSoundOverrides[i] = static_cast(SMemAlloc(sizeof(WorldStateZoneSoundOverride), __FILE__, __LINE__, 0)); + + WorldStateZoneSoundsRec* rec = (static_cast(i) < 0 || static_cast(i) >= g_worldStateZoneSoundsDB.m_numRecords) ? nullptr : &g_worldStateZoneSoundsDB.m_records[i]; + + s_worldStateZoneSoundOverrides[i]->m_areaId = rec->m_areaID; + s_worldStateZoneSoundOverrides[i]->m_wmoAreaId = rec->m_wmoareaID; + s_worldStateZoneSoundOverrides[i]->m_worldStateId = rec->m_worldStateID; + s_worldStateZoneSoundOverrides[i]->m_worldStateValue = rec->m_worldStateValue; + s_worldStateZoneSoundOverrides[i]->m_zoneIntroMusicId = rec->m_zoneIntroMusicID; + s_worldStateZoneSoundOverrides[i]->m_zoneMusicId = rec->m_zoneMusicID; + s_worldStateZoneSoundOverrides[i]->m_soundAmbienceId = rec->m_soundAmbienceID; + s_worldStateZoneSoundOverrides[i]->m_soundProviderPreferencesId = rec->m_soundProviderPreferencesID; + } +} + +// VERIFY: 21e9b526 manual +// OFFSET: 0x004CC2F0 +void SI2::FreeWorldStateZoneSoundOverrides() { + for (uint32_t i = 0; i < s_worldStateZoneSoundOverrides.Count(); i++) { + if (s_worldStateZoneSoundOverrides[i]) { + delete s_worldStateZoneSoundOverrides[i]; + } + } + + s_worldStateZoneSoundOverrides.Clear(); +} + +// VERIFY: 6baa66d7 manual +// OFFSET: 0x004CC620 +void SI2::FreeSoundKitDefs() { + for (uint32_t i = 0; i < s_soundKitDefs.Count(); i++) { + if (s_soundKitDefs[i]) { + delete s_soundKitDefs[i]; + } + } + + s_soundKitDefs.Clear(); + s_soundKitLookup.Clear(); +} + +// VERIFY: b1c83b1a manual +// OFFSET: 0x004CC6E0 +void SI2::FreeZoneSoundOverrides() { + s_zoneSoundOverrides.Clear(); +} + +// VERIFY: 47a145e0 auto +// OFFSET: 0x004CCA30 +int32_t SI2::GetZoneSoundOverride(int32_t mapId, int32_t chunkX, int32_t chunkY, int32_t subchunkX, int32_t subchunkY, int32_t* zoneIntroMusicId, int32_t* zoneMusicId, int32_t* soundAmbienceId, int32_t* soundProviderPreferencesId) { + char key[64]; + SStrPrintf(key, sizeof(key), "%010d_%010d_%010d_%010d_%010d", mapId, chunkX, chunkY, subchunkX, subchunkY); + + ZONESOUNDOVERRIDELOOKUP* lookup = s_zoneSoundOverrides.Ptr(key); + + if (!lookup) { + return 0; + } + + *zoneIntroMusicId = lookup->m_zoneIntroMusicId; + *zoneMusicId = lookup->m_zoneMusicId; + *soundAmbienceId = lookup->m_soundAmbienceId; + *soundProviderPreferencesId = lookup->m_soundProviderPreferencesId; + return 1; +} + +// VERIFY: 6d857c47 auto +// OFFSET: 0x004CCAA0 +int32_t SI2::LookupSoundKitId(const char* name) { + SOUNDKITLOOKUP* lookup = s_soundKitLookup.Ptr(name); + + if (!lookup) { + return 0; + } + + return lookup->m_soundKitId; +} + +// VERIFY: 9c167174 manual +// OFFSET: 0x004CD4A0 +void SI2::InitSoundKitLookup() { + uint32_t count = g_soundEntriesDB.m_maxID + 1; + s_soundKitDefs.SetCount(count); + memset(s_soundKitDefs.Ptr(), 0, sizeof(VSOUNDKITDEF*) * count); + + for (int32_t i = 0; i < g_soundEntriesDB.m_numRecords; i++) { + SoundEntriesRec* rec = (i < 0 || i >= g_soundEntriesDB.m_numRecords) ? nullptr : &g_soundEntriesDB.m_records[i]; + + if (!rec) { + continue; + } + + VSOUNDKITDEF* def = new (SMemAlloc(sizeof(VSOUNDKITDEF), __FILE__, __LINE__, 0)) VSOUNDKITDEF(); + + for (int32_t j = 0; j < 10; j++) { + const char* file = rec->m_file[j]; + + if (!file || !*file) { + break; + } + + size_t length = strlen(file) + 1; + + if (*rec->m_directoryBase) { + length += strlen(rec->m_directoryBase) + 1; + } + + def->m_files[j] = static_cast(calloc(1, length)); + + if (*rec->m_directoryBase) { + bool slash = rec->m_directoryBase[strlen(rec->m_directoryBase) - 1] == '\\'; + sprintf(def->m_files[j], "%s", rec->m_directoryBase); + + if (!slash) { + strcat(def->m_files[j], "\\"); + } + } + + strcat(def->m_files[j], rec->m_file[j]); + + def->m_numFiles++; + def->m_frequencies[j] = rec->m_freq[j]; + } + + def->m_flags = rec->m_flags; + def->m_name = rec->m_name; + def->m_minDistance = rec->m_minDistance; + def->m_distanceCutoff = rec->m_distanceCutoff; + def->m_volume = rec->m_volumeFloat; + def->m_id = rec->m_id; + def->m_advancedId = rec->m_soundEntriesAdvancedID; + def->m_advanced = nullptr; + + if (def->m_advancedId) { + def->m_advanced = g_soundEntriesAdvancedDB.GetRecord(def->m_advancedId); + } + + s_soundKitDefs[rec->m_id] = def; + + SOUNDKITLOOKUP* lookup = s_soundKitLookup.Ptr(rec->m_name); + + if (!lookup) { + lookup = s_soundKitLookup.New(rec->m_name, 0, 0); + } + + lookup->m_soundKitId = rec->m_id; + } +} + +// VERIFY: 17a0acc4 manual +// OFFSET: 0x004CD870 +void SI2::InitZoneSoundOverrides() { + char key[64]; + + for (int32_t i = 0; i < g_worldChunkSoundsDB.m_numRecords; i++) { + WorldChunkSoundsRec* rec = (i < 0 || i >= g_worldChunkSoundsDB.m_numRecords) ? nullptr : &g_worldChunkSoundsDB.m_records[i]; + + SStrPrintf(key, sizeof(key), "%010d_%010d_%010d_%010d_%010d", rec->m_id, rec->m_chunkX, rec->m_chunkY, rec->m_subchunkX, rec->m_subchunkY); + + ZONESOUNDOVERRIDELOOKUP* lookup = s_zoneSoundOverrides.Ptr(key); + + if (!lookup) { + lookup = s_zoneSoundOverrides.New(key, 0, 0); + } + + lookup->m_zoneIntroMusicId = rec->m_zoneIntroMusicID; + lookup->m_zoneMusicId = rec->m_zoneMusicID; + lookup->m_soundAmbienceId = rec->m_soundAmbienceID; + lookup->m_soundProviderPreferencesId = rec->m_soundProviderPreferencesID; + } +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Internal.h b/WoW/Source/SoundInterface/SoundInterface2Internal.h new file mode 100644 index 0000000..5e3a869 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Internal.h @@ -0,0 +1,60 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2INTERNAL_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2INTERNAL_H + +#include +#include +#include "Engine/Source/SoundEngine/fmodex/src/fmod.hpp" +#include "Engine/Source/Storm/H/stpl.h" + +class SoundEntriesAdvancedRec; + +class VSOUNDKITDEF { + public: + /* 0000 */ const char* m_name; + /* 0004 */ char* m_files[10]; + /* 002C */ float m_minDistance; + /* 0030 */ float m_distanceCutoff; + /* 0034 */ float m_volume; + /* 0038 */ int32_t m_id; + /* 003C */ uint32_t m_flags; + /* 0040 */ int32_t m_numFiles; + /* 0044 */ int32_t m_lastIndex; + /* 0048 */ int32_t m_frequencies[10]; + /* 0070 */ int32_t m_weights[10]; + /* 0098 */ FMOD::SoundGroup* m_loadSoundGroup; + /* 009C */ FMOD::SoundGroup* m_soundGroup; + /* 00A0 */ int32_t m_pendingIndex; + /* 00A4 */ int32_t m_downloadPending; + /* 00A8 */ int32_t m_advancedId; + /* 00AC */ SoundEntriesAdvancedRec* m_advanced; + + VSOUNDKITDEF(); + ~VSOUNDKITDEF(); + void ResetWeights(); + const char* SelectFile(uint32_t mode, int32_t* index, int32_t fileIndex, int32_t priority); +}; + +struct SOUNDKITLOOKUP : public TSHashObject { + /* 0018 */ int32_t m_soundKitId; +}; + +struct ZONESOUNDOVERRIDELOOKUP : public TSHashObject { + /* 0018 */ int32_t m_zoneIntroMusicId; + /* 001C */ int32_t m_zoneMusicId; + /* 0020 */ int32_t m_soundAmbienceId; + /* 0024 */ int32_t m_soundProviderPreferencesId; +}; + +class WorldStateZoneSoundOverride { + public: + /* 0000 */ int32_t m_areaId; + /* 0004 */ int32_t m_wmoAreaId; + /* 0008 */ int32_t m_worldStateId; + /* 000C */ int32_t m_worldStateValue; + /* 0010 */ int32_t m_zoneIntroMusicId; + /* 0014 */ int32_t m_zoneMusicId; + /* 0018 */ int32_t m_soundAmbienceId; + /* 001C */ int32_t m_soundProviderPreferencesId; +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2Reverb.cpp b/WoW/Source/SoundInterface/SoundInterface2Reverb.cpp new file mode 100644 index 0000000..4faad7f --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Reverb.cpp @@ -0,0 +1,77 @@ +#include +#include +#include +#include "Engine/Source/SoundEngine/SoundEngine.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +// STATIC: 0x00B4AF2C +static const char* s_reverbDescription; + +// VERIFY: b61935df manual +// OFFSET: 0x004D1EC0 +static void GetReverbProperties(SoundProviderPreferencesRec* rec, FMOD_REVERB_PROPERTIES* properties) { + if (!properties) { + return; + } + + FMOD_REVERB_PROPERTIES off = FMOD_PRESET_OFF; + + if (!rec) { + memcpy(properties, &off, sizeof(FMOD_REVERB_PROPERTIES)); + s_reverbDescription = nullptr; + return; + } + + properties->Instance = 0; + properties->Environment = rec->m_eaxenvironmentSelection; + properties->EnvSize = rec->m_eax2EnvironmentSize; + properties->EnvDiffusion = rec->m_eax2EnvironmentDiffusion; + properties->Room = rec->m_eax2Room; + properties->RoomHF = rec->m_eax2RoomHf; + properties->RoomLF = rec->m_eax3RoomLf; + properties->DecayTime = rec->m_eaxdecayTime; + properties->DecayHFRatio = rec->m_eax2DecayHfratio; + properties->DecayLFRatio = rec->m_eax3DecayLfratio; + properties->Reflections = rec->m_eax2Reflections; + properties->ReflectionsDelay = rec->m_eax2ReflectionsDelay; + properties->Reverb = rec->m_eax2Reverb; + properties->ReverbDelay = rec->m_eax2ReverbDelay; + properties->EchoTime = rec->m_eax3EchoTime; + properties->EchoDepth = rec->m_eax3EchoDepth; + properties->ModulationTime = rec->m_eax3ModulationTime; + properties->ModulationDepth = rec->m_eax3ModulationDepth; + properties->AirAbsorptionHF = rec->m_eax2AirAbsorption; + properties->HFReference = rec->m_eax3Hfreference; + properties->LFReference = rec->m_eax3Lfreference; + properties->Flags = 0x4FF; + properties->RoomRolloffFactor = rec->m_eax2RoomRolloff; + properties->Diffusion = 100.0f; + properties->Density = 100.0f; + properties->ReflectionsPan[0] = 0.0f; + properties->ReflectionsPan[1] = 0.0f; + properties->ReflectionsPan[2] = 0.0f; + properties->ReverbPan[0] = 0.0f; + properties->ReverbPan[1] = 0.0f; + properties->ReverbPan[2] = 0.0f; + + s_reverbDescription = rec->m_description; +} + +// VERIFY: 881e694d manual +// OFFSET: 0x004D2050 +void SI2::ApplyReverbSettings() { + if (!SE2::IsReverbEnabled()) { + return; + } + + FMOD_REVERB_PROPERTIES properties; + GetReverbProperties(g_soundProviderPreferencesDB.GetRecord(SI2::GetZoneReverb()), &properties); + SE2::SetReverb(&properties); +} + +// VERIFY: 8f6ff286 auto +// OFFSET: 0x004D20A0 +void SI2::UpdateReverb() { + SI2::ApplyReverbSettings(); +} diff --git a/WoW/Source/SoundInterface/SoundInterface2VocalErrorSounds.cpp b/WoW/Source/SoundInterface/SoundInterface2VocalErrorSounds.cpp new file mode 100644 index 0000000..0adb20e --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2VocalErrorSounds.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +// STATIC: 0x00DCEAF8 +static int32_t s_vocalErrorSounds[68]; + +// VERIFY: 2b3e2ff2 manual +// OFFSET: 0x00986C90 +void SI2::InitVocalErrorSounds(int32_t race, uint32_t sex) { + memset(s_vocalErrorSounds, 0, sizeof(s_vocalErrorSounds)); + + if (sex > 1) { + return; + } + + for (int32_t i = 0; i < g_vocalUISoundsDB.m_numRecords; i++) { + VocalUISoundsRec* rec = (i < 0 || i >= g_vocalUISoundsDB.m_numRecords) ? nullptr : &g_vocalUISoundsDB.m_records[i]; + + if (rec && rec->m_vocalUienum < 68 && rec->m_raceID == race) { + s_vocalErrorSounds[rec->m_vocalUienum] = rec->m_normalSoundID[sex]; + } + } +} diff --git a/WoW/Source/SoundInterface/SoundInterface2VoiceChat.cpp b/WoW/Source/SoundInterface/SoundInterface2VoiceChat.cpp new file mode 100644 index 0000000..0a9f850 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2VoiceChat.cpp @@ -0,0 +1,392 @@ +#include +#include +#include +#include +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2VoiceChat.h" +#include "Engine/Source/Base/CmdLine.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/Event/Event.h" +#include "Engine/Source/Storm/H/storm.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +// STATIC: 0x00B2D9E4 +static SI2LoopbackCapture s_loopbackCapture; + +// STATIC: 0x00DCEAA4 +static int32_t s_microphoneSignalLevel; + +// STATIC: 0x00DCEAA8 +static uint8_t* s_loopbackBuffer; + +// STATIC: 0x00DCEAAC +static uint8_t* s_loopbackWrite; + +// STATIC: 0x00DCEAB0 +static uint32_t s_loopbackSize; + +// STATIC: 0x00DCEAB4 +static SE2SoundKitObject s_loopbackSound; + +// VERIFY: 5c71868e auto +// OFFSET: 0x00986390 +void SI2::VoiceChat_ShutDownCapture() { + SE2::ShutDownCapture(); +} + +// VERIFY: 92720538 manual +// OFFSET: 0x009863A0 +void SI2::VoiceChat_CleanUpLoopbackSound() { + SI2::StopSound(&s_loopbackSound, 1, -1.0f, 1); + + if (s_loopbackBuffer) { + SMemFree(s_loopbackBuffer, __FILE__, __LINE__, 0); + s_loopbackBuffer = nullptr; + s_loopbackSize = 0; + } +} + +// VERIFY: 313d6efe auto +// OFFSET: 0x009863F0 +void SI2::VoiceChat_StopPlayingLoopbackSound() { + SI2::StopSound(&s_loopbackSound, 1, -1.0f, 1); +} + +// VERIFY: a69f50c4 auto +// OFFSET: 0x00986410 +bool SI2::VoiceChat_IsPlayingLoopbackSound() { + return SI2::IsPlaying(&s_loopbackSound); +} + +// VERIFY: 992daf2d manual +// OFFSET: 0x00986420 +void SI2::VoiceChat_SetCaptureDevice(int32_t index) { + static CVar* s_inputDriverIndex = CVar::Lookup("Sound_VoiceChatInputDriverIndex"); + + if (s_inputDriverIndex) { + char value[32]; + SStrPrintf(value, sizeof(value), "%d", index); + s_inputDriverIndex->Set(value, true, false, false, true); + } +} + +// VERIFY: f9cebc61 manual +// OFFSET: 0x00986490 +void SI2::VoiceChat_SetOutputDevice(int32_t index) { + static CVar* s_outputDriverIndex = CVar::Lookup("Sound_VoiceChatOutputDriverIndex"); + + if (s_outputDriverIndex) { + char value[32]; + SStrPrintf(value, sizeof(value), "%d", index); + s_outputDriverIndex->Set(value, true, false, false, true); + } +} + +// VERIFY: c0b92063 auto +// OFFSET: 0x00986500 +void SI2::VoiceChat_DestroyChatSystem() { + SE2::DestroyChatSystem(); +} + +// VERIFY: b52bb4f6 auto +// OFFSET: 0x00986510 +int32_t SI2::VoiceChat_IsVoiceChatInitialized() { + return SE2::IsChatSoundInitialized(); +} + +// VERIFY: 2b6fed5c auto +// OFFSET: 0x00986520 +void SI2::VoiceChat_AmplifyMicrophoneInput(int16_t* data, uint32_t samples) { + if (!SE2::IsChatSoundInitialized()) { + return; + } + + static CVar* s_outboundChatVolume = CVar::Lookup("OutboundChatVolume"); + + if (!s_outboundChatVolume) { + return; + } + + float volume = s_outboundChatVolume->m_floatValue; + + if (1.0f == volume) { + return; + } + + for (uint32_t i = 0; i < samples; i++) { + int32_t value = static_cast(data[i] * volume); + + if (value < -32768) { + value = -32768; + } else if (value > 32767) { + value = 32767; + } + + data[i] = static_cast(value); + } +} + +// VERIFY: d56d0331 manual +// OFFSET: 0x009865C0 +static void ComputeAverageLevel(float* data, uint32_t count) { + if (!SE2::IsChatSoundInitialized()) { + return; + } + + float sum = 0.0f; + + for (uint32_t i = 0; i < count; i++) { + sum += fabs(data[i]); + } + + s_microphoneSignalLevel = static_cast(sqrt(sum / count) * 100.0f); +} + +// VERIFY: 0f8f8550 auto +// OFFSET: 0x00986670 +int32_t SI2::VoiceChat_GetCurrentMicrophoneSignalLevel() { + return SE2::IsChatSoundInitialized() != 0 ? s_microphoneSignalLevel : 0; +} + +// VERIFY: 124ffd5f auto +// OFFSET: 0x00986680 +int32_t SI2::VoiceChat_CreateChatSound(SE2SoundKitObject* object, SEStreamCallbacks* callbacks, int32_t chatSystem) { + if (!SE2::IsChatSoundInitialized()) { + return 17; + } + + object->m_sound.CreateChatSound(callbacks, chatSystem); + return 0; +} + +// VERIFY: 73c312f2 auto +// OFFSET: 0x009866B0 +int32_t SI2::VoiceChat_Play(SE2SoundKitObject* object) { + if (!SE2::IsChatSoundInitialized()) { + return 17; + } + + object->m_sound.Play(); + return 0; +} + +// VERIFY: eec71328 auto +// OFFSET: 0x009866E0 +static void MonitorCallback(float* data, uint32_t count) { + if (SE2::IsChatSoundInitialized()) { + ComputeAverageLevel(data, count); + } +} + +// VERIFY: e6a66d96 auto +// OFFSET: 0x00986700 +void SI2::VoiceChat_InitCapture(float sampleRate) { + if (CmdLineGetBool(static_cast(26))) { + return; + } + + int32_t outputDriverIndex = 0; + static CVar* s_outputDriverIndex = CVar::Lookup("Sound_VoiceChatOutputDriverIndex"); + + if (s_outputDriverIndex) { + outputDriverIndex = s_outputDriverIndex->m_intValue; + } + + const char* outputDriverName = ""; + static CVar* s_outputDriverName = CVar::Lookup("Sound_VoiceChatOutputDriverName"); + + if (s_outputDriverName) { + outputDriverName = s_outputDriverName->m_stringValue.m_str; + } + + int32_t inputDriverIndex = 0; + static CVar* s_inputDriverIndex = CVar::Lookup("Sound_VoiceChatInputDriverIndex"); + + if (s_inputDriverIndex) { + inputDriverIndex = s_inputDriverIndex->m_intValue; + } + + const char* inputDriverName = ""; + static CVar* s_inputDriverName = CVar::Lookup("Sound_VoiceChatInputDriverName"); + + if (s_inputDriverName) { + inputDriverName = s_inputDriverName->m_stringValue.m_str; + } + + SE2::InitCapture(&outputDriverIndex, outputDriverName, &inputDriverIndex, inputDriverName, sampleRate); + + char value[32]; + + if (s_outputDriverIndex) { + SStrPrintf(value, sizeof(value), "%d", outputDriverIndex); + s_outputDriverIndex->Set(value, true, false, false, true); + } + + if (s_inputDriverName) { + SStrPrintf(value, sizeof(value), "%d", inputDriverIndex); + s_inputDriverIndex->Set(value, true, false, false, true); + } + + SE2::SetUserMonitorDSPCallback(MonitorCallback); +} + +// VERIFY: d0c59c8d auto +// OFFSET: 0x009868A0 +void SI2::VoiceChat_SetPrimaryCaptureCallback(SECaptureCallbacks* callbacks) { + if (SE2::IsChatSoundInitialized()) { + SE2::SetPrimaryCaptureCallback(callbacks); + } +} + +// VERIFY: 57b84183 manual +// OFFSET: 0x009868C0 +void SI2::VoiceChat_StartCapture() { + if (SE2::IsChatSoundInitialized()) { + SE2::StartCapture(); + } +} + +// VERIFY: 77221e3b manual +// OFFSET: 0x009868D0 +void SI2::VoiceChat_StopCapture() { + if (SE2::IsChatSoundInitialized()) { + SE2::StopCapture(); + } +} + +// VERIFY: 67c97745 manual +// OFFSET: 0x009868E0 +static void ComputeMicrophoneLevel(int16_t* data, uint32_t samples) { + if (!SE2::IsChatSoundInitialized()) { + return; + } + + uint32_t sum = 0; + + for (uint32_t i = 0; i < samples; i++) { + sum += abs(data[i]); + } + + s_microphoneSignalLevel = static_cast(sqrt(static_cast(sum / samples) * 0.000030517578f) * 100.0f); +} + +// VERIFY: a6e75762 manual +// OFFSET: 0x00986960 +SI2LoopbackCapture::~SI2LoopbackCapture() { +} + +// VERIFY: 9fa225c6 auto +// OFFSET: 0x00986990 +bool SI2::VoiceChat_IsRecordingLoopbackSound() { + if (!SE2::IsChatSoundInitialized()) { + return false; + } + + return SE2::IsCapturing() && SE2::AlternateCaptureCallbackIsActive(); +} + +// VERIFY: eec9034f manual +// OFFSET: 0x009869C0 +void SI2::VoiceChat_ActivatePrimaryCaptureCallback() { + if (SE2::IsChatSoundInitialized()) { + SE2::ActivatePrimaryCaptureCallback(); + } +} + +// VERIFY: 887239cf auto +// OFFSET: 0x009869D0 +void SI2::VoiceChat_StopRecordingLoopbackSound() { + if (SE2::IsChatSoundInitialized()) { + SI2::VoiceChat_ActivatePrimaryCaptureCallback(); + } +} + +// VERIFY: 075fee4d manual +// OFFSET: 0x009869F0 +void SI2LoopbackCapture::ProcessData(int16_t* data, uint32_t samples) { + if (!s_loopbackBuffer) { + return; + } + + SI2::VoiceChat_AmplifyMicrophoneInput(data, samples); + ComputeMicrophoneLevel(data, samples); + + uint8_t* write = s_loopbackWrite; + uint32_t remaining = static_cast(s_loopbackBuffer + s_loopbackSize - write); + uint32_t bytes = 2 * samples; + + if (bytes >= remaining) { + bytes = remaining; + } + + memcpy(write, data, 2 * (bytes >> 1)); + s_loopbackWrite = write + bytes; + + if (!remaining && SE2::IsChatSoundInitialized()) { + SI2::VoiceChat_ActivatePrimaryCaptureCallback(); + } +} + +// VERIFY: 0dc037b8 auto +// OFFSET: 0x00986A70 +static int32_t DetectRecordingFinished(const void* data, void* param) { + if (!SE2::IsChatSoundInitialized() || !SE2::IsCapturing() || !SE2::AlternateCaptureCallbackIsActive()) { + EventUnregister(EVENT_ID_POLL, DetectRecordingFinished); + } + + return 1; +} + +// VERIFY: 0741bfdd manual +// OFFSET: 0x00986AA0 +void SI2::VoiceChat_RecordLoopbackSound(int32_t seconds) { + if (!SE2::IsChatSoundInitialized()) { + return; + } + + SI2::VoiceChat_CleanUpLoopbackSound(); + + s_loopbackSize = 16000 * seconds + 44; + + uint32_t* header = static_cast(SMemAlloc(16000 * seconds + 44, __FILE__, __LINE__, SMEM_FLAG_ZEROMEMORY)); + header[0] = 'FFIR'; + header[1] = 16000 * seconds + 32; + header[2] = 'EVAW'; + header[3] = ' tmf'; + header[4] = 16; + header[5] = 0x10001; + s_loopbackBuffer = reinterpret_cast(header); + header[6] = 8000; + header[7] = 16000; + header[8] = 0x100002; + header[9] = 'atad'; + header[10] = 16000 * seconds; + s_loopbackWrite = reinterpret_cast(&header[11]); + + SE2::SetAlternateCaptureCallback(&s_loopbackCapture); + SE2::ActivateAlternateCaptureCallback(); + EventRegister(EVENT_ID_POLL, DetectRecordingFinished); +} + +// VERIFY: ef5b70e1 manual +// OFFSET: 0x00986BC0 +void SI2::VoiceChat_PlayLoopbackSound() { + if (!SE2::IsChatSoundInitialized() || !s_loopbackBuffer) { + return; + } + + s_loopbackSound.m_sound.PlaySoundFromMemory(reinterpret_cast(s_loopbackBuffer), s_loopbackSize, 1); + + SI2SoundUserData* userData = new (SMemAlloc(sizeof(SI2SoundUserData), __FILE__, __LINE__, 0)) SI2SoundUserData(); + userData->m_name = ""; + userData->m_soundKitId = 0; + userData->m_def = nullptr; + userData->m_group = 3; + + s_loopbackSound.m_sound.SetUserData(userData); + s_loopbackSound.m_sound.SetFinishedCallback(SI2::SoundFinished, nullptr); + s_loopbackSound.m_sound.SetChannelGroup(SI2::s_channelGroupNames[userData->m_group], userData->m_group != 3); + SE2::AttachMonitorDSP(&s_loopbackSound.m_sound); + s_loopbackSound.m_sound.Play(); +} diff --git a/WoW/Source/SoundInterface/SoundInterface2VoiceChat.h b/WoW/Source/SoundInterface/SoundInterface2VoiceChat.h new file mode 100644 index 0000000..c571829 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2VoiceChat.h @@ -0,0 +1,14 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2VOICECHAT_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2VOICECHAT_H + +#include +#include +#include "Engine/Source/SoundEngine/SoundEngine.h" + +class SI2LoopbackCapture : public SECaptureCallbacks { + public: + virtual ~SI2LoopbackCapture(); + virtual void ProcessData(int16_t* data, uint32_t samples); +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2Water.cpp b/WoW/Source/SoundInterface/SoundInterface2Water.cpp new file mode 100644 index 0000000..11a2409 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Water.cpp @@ -0,0 +1,15 @@ +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2Water.h" +#include "Engine/Source/Event/Event.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +// STATIC: 0x00B4AF5C +static SI2WaterSound s_nearestWaterSounds[1]; + +// VERIFY: cf194119 auto +// OFFSET: 0x004D2750 +void SI2::WaterShutdown() { + SI2::StopSound(&s_nearestWaterSounds[0].m_object, 0, -1.0f, 1); + EventUnregister(EVENT_ID_IDLE, SI2::HandleWaterSounds); +} diff --git a/WoW/Source/SoundInterface/SoundInterface2Water.h b/WoW/Source/SoundInterface/SoundInterface2Water.h new file mode 100644 index 0000000..b9b1f83 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2Water.h @@ -0,0 +1,18 @@ +#ifndef WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2WATER_H +#define WOW_SOURCE_SOUNDINTERFACE_SOUNDINTERFACE2WATER_H + +#include +#include +#include "Engine/Source/Tempest/C3Vector.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" + +struct SI2WaterSound { + /* 0000 */ float m_distanceSq; + /* 0004 */ C3Vector m_position; + /* 0010 */ int32_t m_soundKitId; + /* 0014 */ SE2SoundKitObject m_object; + /* 0028 */ int32_t m_valid; + /* 002C */ int32_t m_moved; +}; + +#endif diff --git a/WoW/Source/SoundInterface/SoundInterface2ZoneSounds.cpp b/WoW/Source/SoundInterface/SoundInterface2ZoneSounds.cpp new file mode 100644 index 0000000..06b8a40 --- /dev/null +++ b/WoW/Source/SoundInterface/SoundInterface2ZoneSounds.cpp @@ -0,0 +1,660 @@ +#include +#include +#include +#include "WoW/Source/SoundInterface/SoundInterface2ZoneSounds.h" +#include "Engine/Source/BlizzardCore/SFile2-Core.h" +#include "Engine/Source/ConsoleBase/ConsoleVar.h" +#include "Engine/Source/Event/Event.h" +#include "Engine/Source/Os/TimeManager.h" +#include "Engine/Source/Storm/H/storm.h" +#include "Engine/Source/Tempest/CRandom.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/Game/GameTime.h" +#include "WoW/Source/SoundInterface/SoundInterface2.h" +#include "WoW/Source/Ui/GameUI.h" + +// STATIC: 0x00AC3878 +static int32_t s_zoneSoundTimeOfDay = 1; + +// STATIC: 0x00B4AAB0 +static SI2ZoneSoundInfo s_zoneSounds[11]; + +// STATIC: 0x00B4AC3C +static SE2SoundKitObject s_scriptMusic; + +// STATIC: 0x00B4AC50 +static SI2ZoneSoundPair s_zoneAmbience; + +// STATIC: 0x00B4AC90 +static SI2ZoneSoundPair s_zoneMusic; + +// STATIC: 0x00B4ACD0 +TSGrowableArray SI2::sm_aIntroMusicNextValidPlayTime; + +// VERIFY: e6578ba5 manual +// OFFSET: 0x004C8590 +int32_t SI2::GetZoneReverb() { + for (int32_t i = 10; i >= 0; i--) { + if (s_zoneSounds[i].m_reverb < 0) { + continue; + } + + if (i == 9) { + if (!SI2::sm_bCameraIsUnderwater) { + continue; + } + } else if (i == 8 && SI2::sm_bPlayerInside) { + continue; + } + + return s_zoneSounds[i].m_reverb; + } + + return 0; +} + +// VERIFY: 368f23da auto +// OFFSET: 0x004C85F0 +void SI2::StopZoneAmbience() { + s_zoneAmbience.Stop(1); +} + +// VERIFY: 481f5672 auto +// OFFSET: 0x004C8600 +void SI2::SetPlayerInside(bool inside) { + SI2::sm_bPlayerInside = inside; +} + +// VERIFY: b619fbdd auto +// OFFSET: 0x004C8610 +void SI2::SetWeatherKitID(int32_t soundKitId) { + s_zoneSounds[8].m_ambience[0] = soundKitId; + s_zoneSounds[8].m_ambience[1] = soundKitId; +} + +// VERIFY: 92518c26 auto +// OFFSET: 0x004C8630 +void SI2::SetUnderwaterStatus(int32_t underwater) { + int32_t unchanged = underwater == SI2::sm_bCameraIsUnderwater; + SI2::sm_bCameraIsUnderwater = underwater; + s_zoneSounds[9].m_ambience[0] = underwater ? 4209 : -1; + s_zoneSounds[9].m_ambience[1] = s_zoneSounds[9].m_ambience[0]; + SI2::sm_bUnderwaterChanged = !unchanged; + SI2::UpdateReverb(); +} + +// VERIFY: 8cc2bd07 auto +// OFFSET: 0x004C8670 +int32_t SI2::IsUnderwater() { + return SI2::sm_bCameraIsUnderwater; +} + +// VERIFY: 3dfce48c auto +// OFFSET: 0x004C8680 +void SI2::StopLuaMusic() { + SI2::StopSound(&s_scriptMusic, 0, 0.5f, 1); + SI2::sm_bLuaMusicPlaying = 0; +} + +// VERIFY: 527bb7b0 auto +// OFFSET: 0x004C86B0 +void SI2::SetZoneReverb(int32_t type, int32_t reverb) { + s_zoneSounds[type].m_reverb = reverb; + SI2::ApplyReverbSettings(); +} + +// VERIFY: 53308ceb auto +// OFFSET: 0x004C86D0 +void SI2::SetZoneUnderwaterReverb(int32_t reverb) { + s_zoneSounds[9].m_reverb = reverb; + SI2::ApplyReverbSettings(); +} + +// VERIFY: a9775166 auto +// OFFSET: 0x004C86F0 +int32_t SI2::GetDesiredAmbienceKitID(int32_t* type) { + static CVar* s_enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + static CVar* s_enableAmbience = CVar::Lookup("Sound_EnableAmbience"); + + if ((s_enableAllSound && !s_enableAllSound->m_intValue) || (s_enableAmbience && !s_enableAmbience->m_intValue) || CGGameUI::m_inMovie) { + if (type) { + *type = 14; + } + + return 0; + } + + for (int32_t i = 10; i >= 0; i--) { + if (s_zoneSounds[i].m_ambience[s_zoneSoundTimeOfDay] < 0 || (i == 8 && SI2::sm_bPlayerInside)) { + continue; + } + + if (type) { + *type = i; + } + + return s_zoneSounds[i].m_ambience[s_zoneSoundTimeOfDay]; + } + + return 0; +} + +// VERIFY: 40642125 auto +// OFFSET: 0x004C87D0 +int32_t SI2::ZoneMusicDelayElapsed(int32_t type) { + if (type && type != 2 && type != 1) { + return 1; + } + + static CVar* s_zoneMusicNoDelay = CVar::Lookup("Sound_ZoneMusicNoDelay"); + + return (s_zoneMusicNoDelay && s_zoneMusicNoDelay->m_intValue) || OsGetAsyncTimeMs() >= SI2::sm_nextZoneMusicTime; +} + +// VERIFY: 97d2bfe2 auto +// OFFSET: 0x004C8830 +int32_t SI2::IntroMusicOkToPlay(int32_t soundKitId, int32_t type) { + if (soundKitId == s_zoneMusic.GetPlayingSoundKitId() || (type != 5 && type != 7 && type != 6)) { + return 1; + } + + if (s_zoneMusic.GetCurrentType() == 5) { + return 0; + } + + if (s_zoneMusic.GetCurrentType() == 7) { + return 0; + } + + if (s_zoneMusic.GetCurrentType() == 6) { + return 0; + } + + uint32_t now = OsGetAsyncTimeMs(); + + if (static_cast(soundKitId) >= SI2::sm_aIntroMusicNextValidPlayTime.Count()) { + return 0; + } + + return now >= SI2::sm_aIntroMusicNextValidPlayTime[soundKitId]; +} + +// VERIFY: 17672894 auto +// OFFSET: 0x004C88B0 +int32_t SI2::GetDesiredMusicKitID(int32_t* type, int32_t* silenceMin, int32_t* silenceMax) { + static CVar* s_enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + static CVar* s_enableMusic = CVar::Lookup("Sound_EnableMusic"); + + if ((s_enableAllSound && !s_enableAllSound->m_intValue) || (s_enableMusic && !s_enableMusic->m_intValue) || CGGameUI::m_inMovie) { + if (type) { + *type = 14; + } + + if (silenceMin) { + *silenceMin = 0; + } + + if (silenceMax) { + *silenceMax = 0; + } + + return 0; + } + + for (int32_t i = 10; i >= 0; i--) { + if ((i == 5 || i == 7 || i == 6) && s_zoneMusic.IsPlaying() && (s_zoneMusic.GetCurrentType() == 5 || s_zoneMusic.GetCurrentType() == 7 || s_zoneMusic.GetCurrentType() == 6)) { + if (i == 8 && SI2::sm_bPlayerInside) { + continue; + } + + if (type) { + *type = s_zoneMusic.GetCurrentType(); + } + + if (silenceMin) { + *silenceMin = 0; + } + + if (silenceMax) { + *silenceMax = 0; + } + + return s_zoneMusic.GetPlayingSoundKitId(); + } + + if (s_zoneSounds[i].m_music[s_zoneSoundTimeOfDay] < 0) { + continue; + } + + if (!SI2::ZoneMusicDelayElapsed(i)) { + if (type) { + *type = 12; + } + + if (silenceMin) { + *silenceMin = 0; + } + + if (silenceMax) { + *silenceMax = 0; + } + + return -1111; + } + + if (!SI2::IntroMusicOkToPlay(s_zoneSounds[i].m_music[s_zoneSoundTimeOfDay], i)) { + continue; + } + + if (type) { + *type = i; + } + + if (silenceMin) { + *silenceMin = s_zoneSounds[i].m_silenceMin[s_zoneSoundTimeOfDay]; + } + + if (silenceMax) { + *silenceMax = s_zoneSounds[i].m_silenceMax[s_zoneSoundTimeOfDay]; + } + + return s_zoneSounds[i].m_music[s_zoneSoundTimeOfDay]; + } + + return 0; +} + +// VERIFY: e4136c86 manual +// OFFSET: 0x004C8AB0 +void SI2::ZoneMusicFinished(SESound* sound, void* param) { + SI2ZoneMusicTimer* timer = static_cast(param); + uint32_t now = OsGetAsyncTimeMs(); + + if (SI2::GetDesiredMusicKitID(nullptr, nullptr, nullptr) == timer->m_soundKitId) { + uint32_t silenceMax = timer->m_silenceMax; + uint32_t silenceMin = timer->m_silenceMin; + + if (silenceMax > silenceMin) { + static CRndSeed s_seed(0); + SI2::sm_nextZoneMusicTime = now + silenceMin + static_cast((static_cast(silenceMax - silenceMin) * CRandom::uint32_(s_seed)) >> 32); + } else { + SI2::sm_nextZoneMusicTime = now + silenceMax; + } + } else { + SI2::sm_nextZoneMusicTime = 0; + } + + delete timer; +} + +// VERIFY: 4b8e2a85 manual +// OFFSET: 0x004C8C90 +void SI2::SetZoneAmbienceID(int32_t type, int32_t soundAmbienceId) { + SoundAmbienceRec* rec = g_soundAmbienceDB.GetRecord(soundAmbienceId); + + if (rec) { + s_zoneSounds[type].m_ambience[0] = rec->m_ambienceID[0]; + s_zoneSounds[type].m_ambience[1] = rec->m_ambienceID[1]; + } else { + s_zoneSounds[type].m_ambience[0] = -1; + s_zoneSounds[type].m_ambience[1] = -1; + } +} + +// VERIFY: 436a05e0 manual +// OFFSET: 0x004C8CF0 +void SI2::SetZoneIntroMusicID(int32_t type, int32_t zoneIntroMusicId) { + ZoneIntroMusicTableRec* rec = g_zoneIntroMusicTableDB.GetRecord(zoneIntroMusicId); + + if (rec) { + s_zoneSounds[type].m_music[0] = rec->m_soundID; + s_zoneSounds[type].m_music[1] = rec->m_soundID; + s_zoneSounds[type].m_silenceMin[0] = rec->m_minDelayMinutes; + s_zoneSounds[type].m_silenceMin[1] = rec->m_minDelayMinutes; + } else { + s_zoneSounds[type].m_music[0] = -1; + s_zoneSounds[type].m_music[1] = -1; + s_zoneSounds[type].m_silenceMin[0] = 0; + s_zoneSounds[type].m_silenceMin[1] = 0; + s_zoneSounds[type].m_silenceMax[0] = 0; + s_zoneSounds[type].m_silenceMax[1] = 0; + } +} + +// VERIFY: 8c58a8a2 manual +// OFFSET: 0x004C8D80 +void SI2::SetZoneMusicID(int32_t type, int32_t zoneMusicId) { + ZoneMusicRec* rec = g_zoneMusicDB.GetRecord(zoneMusicId); + + if (!rec) { + s_zoneSounds[type].m_music[0] = -1; + s_zoneSounds[type].m_music[1] = -1; + s_zoneSounds[type].m_silenceMin[0] = 0; + s_zoneSounds[type].m_silenceMin[1] = 0; + s_zoneSounds[type].m_silenceMax[0] = 0; + s_zoneSounds[type].m_silenceMax[1] = 0; + + if (zoneMusicId > 0) { + SI2::sm_nextZoneMusicTime = 0; + } + + return; + } + + s_zoneSounds[type].m_music[0] = rec->m_sounds[0]; + s_zoneSounds[type].m_music[1] = rec->m_sounds[1]; + s_zoneSounds[type].m_silenceMin[0] = rec->m_silenceIntervalMin[0]; + s_zoneSounds[type].m_silenceMin[1] = rec->m_silenceIntervalMin[1]; + s_zoneSounds[type].m_silenceMax[0] = rec->m_silenceIntervalMax[0]; + s_zoneSounds[type].m_silenceMax[1] = rec->m_silenceIntervalMax[1]; + + int32_t desired = SI2::GetDesiredMusicKitID(nullptr, nullptr, nullptr); + + if (desired != s_zoneMusic.GetPlayingSoundKitId() && (type > 2 || desired != -1111)) { + SI2::sm_nextZoneMusicTime = 0; + } +} + +// VERIFY: c27c3281 manual +// OFFSET: 0x004C8FA0 +void SI2::SetOverrideZoneSounds(int32_t soundAmbienceId, int32_t zoneMusicId) { + SI2::SetZoneAmbienceID(10, soundAmbienceId); + SI2::SetZoneMusicID(10, zoneMusicId); +} + +// VERIFY: 039f2ed0 auto +// OFFSET: 0x004C8FC0 +int32_t SI2::PlayUISound(int32_t soundKitId) { + static int32_t s_voiceChatOn = SI2::LookupSoundKitId("VoiceChatOn"); + static int32_t s_voiceChatOff = SI2::LookupSoundKitId("VoiceChatOff"); + + SE2SoundKitProperties properties; + properties.ResetToDefaults(); + + if (soundKitId == s_voiceChatOn || soundKitId == s_voiceChatOff) { + properties.m_group = 3; + } + + properties.m_priority = 128; + properties.m_suppressorMode = 2; + properties.m_reverb = 0; + + return SI2::PlaySoundKit(soundKitId, nullptr, nullptr, &properties, 0, nullptr, 1, 0); +} + +// VERIFY: cf1057e2 manual +// OFFSET: 0x004C9080 +void SI2::IntroMusicFinished(SESound* sound, void* param) { + SI2ZoneMusicTimer* timer = static_cast(param); + int32_t minutes = timer->m_silenceMin; + uint32_t soundKitId = timer->m_soundKitId; + uint32_t now = OsGetAsyncTimeMs(); + + if (soundKitId < SI2::sm_aIntroMusicNextValidPlayTime.Count()) { + SI2::sm_aIntroMusicNextValidPlayTime[soundKitId] = now + 60000 * minutes; + } + + delete timer; +} + +// VERIFY: a0e10314 manual +// OFFSET: 0x004C90C0 +void SI2::AIMusicFinished(SESound* sound, void* param) { + s_zoneSounds[3].m_music[0] = -1; + s_zoneSounds[3].m_music[1] = -1; + s_zoneSounds[3].m_silenceMin[0] = 0; + s_zoneSounds[3].m_silenceMin[1] = 0; + s_zoneSounds[3].m_silenceMax[0] = 0; + s_zoneSounds[3].m_silenceMax[1] = 0; + s_zoneSounds[3].m_ambience[0] = -1; + s_zoneSounds[3].m_ambience[1] = -1; + s_zoneSounds[3].m_reverb = -1; + + if (param) { + delete static_cast(param); + } +} + +// VERIFY: 26708b3b manual +// OFFSET: 0x004C9110 +int32_t SI2::PlaySoundFile(const char* filename, int32_t group) { + static CVar* s_enableAllSound = CVar::Lookup("Sound_EnableAllSound"); + + if (!s_enableAllSound || !s_enableAllSound->m_intValue || CGGameUI::m_inMovie) { + return 17; + } + + if (group == 5) { + static CVar* s_enableMusic = CVar::Lookup("Sound_EnableMusic"); + + if (!s_enableMusic || !s_enableMusic->m_intValue) { + return 10; + } + } + + SESound localSound; + SESound* sound = group == 5 ? &s_scriptMusic.m_sound : &localSound; + + sound->Create2D(filename, group != 4, nullptr, nullptr, false, false, 0, group != 5 ? 128 : 100, 0xFFFFFFFF); + sound->SetChannelGroup(SI2::s_channelGroupNames[group], true); + + SI2SoundUserData* userData = new (SMemAlloc(sizeof(SI2SoundUserData), __FILE__, __LINE__, 0)) SI2SoundUserData(); + + if (userData) { + userData->m_name = group != 4 ? "