Batch #16351 by ragnarok-clanker: no function's compiled code changes; checked with 784 compiled unit(s), including every includer of Source/Archive/GPak.h, Source/Client/Browser/BrowserCommandTarget.h, Source/Client/Browser/BrowserDocumentUI.h, Source/Client/Browser/BrowserInPlace.h, Source/Client/Browser/WebBrowser.h, Source/Client/Input/Language.h, Source/Client/Input/LanguageTC.h, Source/Client/Input/Mouse.h, Source/Client/Mode/CGameMode.h, Source/Client/Mode/CLoginMode.h, Source/Client/Replay.h, Source/Client/Session.h, Source/Client/Stove/StovePCSDK.h, Source/Contents/AchievementMgr.h, Source/Contents/Actors/CharacterRender.h, Source/Contents/Actors/EffectActors.h, Source/Contents/Actors/GameActor.h, Source/Contents/Actors/GndRiser.h, Source/Contents/Actors/GrannyGameActor.h, Source/Contents/Actors/MousePointer.h, Source/Contents/Actors/Npc.h, Source/Contents/Actors/Pc.h, Source/Contents/Actors/RenderObjectState.h, Source/Contents/Actors/Skill.h, Source/Contents/AdventureGuideMgr.h, Source/Contents/CashEmotionMgr.h, Source/Contents/ClanInfo.h, Source/Contents/Configuration/GameSettingsMgr.h, Source/Contents/EffectResourceSwitcher.h, Source/Contents/Effects/AcidifiedThrow.h, Source/Contents/Effects/ArrowEffect.h, Source/Contents/Effects/AxeBoomerang.h, Source/Contents/Effects/BlastForge.h, Source/Contents/Effects/CharacterParticleBundle.h, Source/Contents/Effects/DummyEffectLauncher.h, Source/Contents/Effects/EZ2STREffectEx.h, Source/Contents/Effects/Effect.h, Source/Contents/Effects/EffectActor.h, Source/Contents/Effects/EffectEmitter.h, Source/Contents/Effects/EffectPrimitiveState.h, Source/Contents/Effects/EffectTypes.h, Source/Contents/Effects/ElectricEffect.h, Source/Contents/Effects/EmitterEffect.h, Source/Contents/Effects/FortuneKissEffect.h, Source/Contents/Effects/MagicFloorEffect.h, Source/Contents/Effects/MandraAttackEffect.h, Source/Contents/Effects/MonsterSkillEffects.h, Source/Contents/Effects/MsgEffect.h, Source/Contents/Effects/Particle.h, Source/Contents/Effects/RagEffectState.h, Source/Contents/Effects/RichManKim.h, Source/Contents/Effects/SpriteParticle.h, Source/Contents/Effects/StarEffect.h, Source/Contents/Effects/WhirlwindEffect.h, Source/Contents/EnchantMgr.h, Source/Contents/FlyingShipRouteInfo.h, Source/Contents/Ground/GroundSpatial.h, Source/Contents/GuildInfo.h, Source/Contents/Hotkeys/InterfaceHotkey.h, Source/Contents/Items/ItemInfo.h, Source/Contents/Items/RuneSystem.h, Source/Contents/MapSkyMgr.h, Source/Contents/Models/ModelActor.h, Source/Contents/Movies/BinkMovie.h, Source/Contents/NavigationManager.h, Source/Contents/Party/PartyBookingMgr.h, Source/Contents/PetEvolutionMgr.h, Source/Contents/RenewQuestMgr.h, Source/Contents/RodexMailStore.h, Source/Contents/Schedule/Schedule.h, Source/Contents/Schedule/ShutDownSchedule.h, Source/Contents/SignBoard/SignBoard.h, Source/Contents/Skills/PlayerSkillBundle.h, Source/Contents/Sound/SoundMgr.h, Source/Contents/SpriteLayerDrawing.h, Source/Contents/Store/MCStoreInfoBackupAsyncWork.h, Source/Contents/UserData/AccountLinkedUserDataLoadAsyncWork.h, Source/Contents/UserData/NormalItemSlots.h, Source/Contents/WorldView/WorldViewData.h, Source/Network/Connection/Connection.h, Source/Render/DX7/DeviceOwnerDX7.h, Source/Render/DX7/DirectDrawEnumeration.h, Source/Render/DX9/DeviceOwnerDX9.h, Source/Render/Primitives/LightmappedPrimitive.h, Source/Render/Primitives/RenderPrimitive.h, Source/Render/Renderer.h, Source/Render/RendererDX7.h, Source/Render/Text/EmbedFont.h, Source/Render/Text/TextContext.h, Source/Render/Textures/Texture.h, Source/Resource/BinkRuntime.h, Source/Resource/GifResource.h, Source/Resource/Models/AnimatedModelResource.h, Source/Resource/Models/GrannyModelResource.h, Source/Resource/Models/ModelMesh.h, Source/Resource/ResourceMgr.h, Source/Resource/World/GroundResource.h, Source/Resource/World/WorldResource.h, Source/Security/NProtectGameGuardMgr.h, Source/Security/ReassemblyPacketMgr.h, Source/UI/Buttons/UIBmpRadioBtn.h, Source/UI/Buttons/UIBmpTextButton2.h, Source/UI/Buttons/UIDescriptRace.h, Source/UI/Buttons/UIItemTagButton.h, Source/UI/Buttons/UITVTextButton.h, Source/UI/Buttons/UITextureButton.h, Source/UI/Chat/UINewChatWnd.h, Source/UI/Chat/UISubChatHisWnd.h, Source/UI/Dialogs/UILoadingWnd.h, Source/UI/Dialogs/UIMiniMapWnd.h, Source/UI/Dialogs/UIPasswordWnd.h, Source/UI/Dialogs/UIRestartWnd.h, Source/UI/Dialogs/UISayDialogWnd.h, Source/UI/Edit/UIEditCtrl.h, Source/UI/Enchant/EnchantUI.h, Source/UI/GameSettings/GameSettingsUI.h, Source/UI/Guild/UIGuildWnd.h, Source/UI/Item/UIItemStoreFindWnd.h, Source/UI/Item/UIItemStoreSubWnd.h, Source/UI/Item/UIItemStoreWnd.h, Source/UI/Items/UIEquipWnd.h, Source/UI/Items/UIExchangeWnd.h, Source/UI/Items/UIItemCollectionWnd.h, Source/UI/Items/UIItemRepairWnd.h, Source/UI/Items/UISwapEquipmentWnd.h, Source/UI/Lists/TableBox.h, Source/UI/Lists/UIListBox.h, Source/UI/Lists/UIListBoxEx.h, Source/UI/Lists/UIListBoxID.h, Source/UI/Lists/UIListBoxTemplate.h, Source/UI/Lists/UITabControl.h, Source/UI/Lists/UITreeView.h, Source/UI/Lists/UIVScrollBar.h, Source/UI/Navigation/UINavigationV4Wnd.h, Source/UI/Navigation/UIPrivateAirplaneWnd.h, Source/UI/Party/UIAdvenPartyBoardWnd.h, Source/UI/Party/UIRequestJoinPartyWnd.h, Source/UI/ProbabilityTable/UIProbabilityTable.h, Source/UI/Quest/UIRenewQuestWnd.h, Source/UI/Rodex/UIRodexComposeWnd.h, Source/UI/RuneSystem/UIRuneSystemWindows.h, Source/UI/RuneSystem/UIRuneSystemWnd.h, Source/UI/Shop/UIMerchantItemMyShopWnd.h, Source/UI/Shop/UIMerchantShopMakeWnd.h, Source/UI/Shop/UIMerchantShopTitle.h, Source/UI/StylingShop/UIStylingShopWnd.h, Source/UI/Text/CreateLineInfo.h, Source/UI/Text/TextMarkup.h, Source/UI/Text/UIString.h, Source/UI/Text/UITextViewer.h, Source/UI/Text/UITransBalloonText.h, Source/UI/UIChangeMaterialWnd.h, Source/UI/UIMacroDetectorWnd.h, Source/UI/UIMacroUserInfoWnd.h, Source/UI/Window/UIAccountLimitedToolWnd.h, Source/UI/Window/UIBalloonOpenBtn.h, Source/UI/Window/UIBasicInfoWnd.h, Source/UI/Window/UIBattleMsgOptionWnd.h, Source/UI/Window/UICollectionSystemWnd.h, Source/UI/Window/UIControl.h, Source/UI/Window/UIHotKeyWnd.h, Source/UI/Window/UIJobListWnd.h, Source/UI/Window/UILoginWnd.h, Source/UI/Window/UIMakeCharWnd.h, Source/UI/Window/UIMerInfoWnd.h, Source/UI/Window/UIMessageBox.h, Source/UI/Window/UIMonsterDisplayWnd.h, Source/UI/Window/UINewMakeCharWnd.h, Source/UI/Window/UINewSkillListWnd.h, Source/UI/Window/UINoticeWnd.h, Source/UI/Window/UIReplayRECControlWnd.h, Source/UI/Window/UIRoMapWnd.h, Source/UI/Window/UISecondCostumeWnd.h, Source/UI/Window/UISeekPartyListWnd.h, Source/UI/Window/UISeekPartyMBWnd.h, Source/UI/Window/UISeekPartyWnd.h, Source/UI/Window/UISerachStoreInfoWnd.h, Source/UI/Window/UIWindow.h, Source/UI/Window/UIWindowMgr.h, Source/UI/Window/WindowId.h, Source/Utility/Async/NAsyncWork.h, Source/Utility/Async/NRecycleObjectPoolMgr.h, Source/Utility/JsonCppLoader.h, Source/Utility/Lexicon/LexiconSerializer.h, Source/Utility/NFileLog.h, Source/Utility/Threading/NThread.h.
696 lines
16 KiB
C++
696 lines
16 KiB
C++
#include "Contents/Configuration/ServiceOptions.h"
|
|
#include "Contents/Sound/SoundConfiguration.h"
|
|
#include "Contents/Sound/SoundMgr.h"
|
|
#include "Resource/ResourceMgr.h"
|
|
#include "Resource/Audio/WaveResource.h"
|
|
#include "Utility/Math/AffineMatrix.h"
|
|
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <new>
|
|
#include <process.h>
|
|
|
|
extern template bool std::_Traits_equal<std::char_traits<char>>(const char*, std::size_t, const char*, std::size_t) noexcept;
|
|
|
|
// STATIC: 0x0138BE7C
|
|
// GLOBAL: gl_24457
|
|
CSoundMgr* g_soundMgr = nullptr;
|
|
|
|
namespace {
|
|
// OFFSET: 0x00401090
|
|
// FUNCTION: fn_45443
|
|
void ShutdownMilesAtExit() {
|
|
MilesRuntime::Get().shutdown();
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00638A90
|
|
// FUNCTION: fn_45421
|
|
CSoundMgr::CSoundMgr() {
|
|
if (this->Initialize()) {
|
|
this->initialized = 1;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00638C40
|
|
// FUNCTION: fn_45422
|
|
CSoundMgr::~CSoundMgr() {
|
|
this->Shutdown();
|
|
}
|
|
|
|
// OFFSET: 0x00638E80
|
|
// FUNCTION: fn_04747
|
|
void CSoundMgr::FadeIn() {
|
|
if (this->threadId != 0) {
|
|
PostThreadMessageA(this->threadId, WM_USER, 0, 0);
|
|
this->threadId = 0;
|
|
}
|
|
|
|
if (this->fadeThread != INVALID_HANDLE_VALUE) {
|
|
WaitForSingleObject(this->fadeThread, 30);
|
|
CloseHandle(this->fadeThread);
|
|
this->fadeThread = INVALID_HANDLE_VALUE;
|
|
}
|
|
|
|
this->fadeThread = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, &CSoundMgr::FadeThread, reinterpret_cast<void*>(1), 0, &this->threadId));
|
|
}
|
|
|
|
// OFFSET: 0x00638EF0
|
|
// FUNCTION: fn_04748
|
|
void CSoundMgr::FadeOut() {
|
|
if (this->threadId != 0) {
|
|
PostThreadMessageA(this->threadId, WM_USER, 0, 0);
|
|
this->threadId = 0;
|
|
}
|
|
|
|
if (this->fadeThread != INVALID_HANDLE_VALUE) {
|
|
WaitForSingleObject(this->fadeThread, 30);
|
|
CloseHandle(this->fadeThread);
|
|
this->fadeThread = INVALID_HANDLE_VALUE;
|
|
}
|
|
|
|
this->fadeThread = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, &CSoundMgr::FadeThread, nullptr, 0, &this->threadId));
|
|
}
|
|
|
|
// OFFSET: 0x00638F60
|
|
// FUNCTION: fn_04749
|
|
void CSoundMgr::StopStreams() {
|
|
this->currentName = std::string();
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
if (this->stream) {
|
|
miles.closeStream(this->stream);
|
|
this->stream = nullptr;
|
|
}
|
|
|
|
if (this->secondaryStream) {
|
|
miles.closeStream(this->secondaryStream);
|
|
this->secondaryStream = nullptr;
|
|
}
|
|
|
|
this->secondaryEnabled = 0;
|
|
}
|
|
|
|
// OFFSET: 0x00639070
|
|
// FUNCTION: fn_04750
|
|
bool CSoundMgr::Initialize() {
|
|
for (int i = 0; i < 48; ++i) {
|
|
this->samples[i] = nullptr;
|
|
}
|
|
|
|
for (int i = 0; i < 48; ++i) {
|
|
this->samples3D[i] = nullptr;
|
|
}
|
|
|
|
for (int i = 0; i < 64; ++i) {
|
|
this->providerNames[i] = nullptr;
|
|
this->providers[i] = 0;
|
|
}
|
|
|
|
SoundConfiguration& configuration = g_soundConfiguration;
|
|
|
|
if (configuration.mode == 0) {
|
|
return true;
|
|
}
|
|
|
|
switch (configuration.numSampleType) {
|
|
case 0:
|
|
this->sampleCount = 48;
|
|
this->sample3DCount = 48;
|
|
break;
|
|
case 1:
|
|
this->sampleCount = 32;
|
|
this->sample3DCount = 32;
|
|
break;
|
|
default:
|
|
this->sampleCount = 16;
|
|
this->sample3DCount = 16;
|
|
break;
|
|
}
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
miles.setRedistDirectory(".\\");
|
|
|
|
std::atexit(&ShutdownMilesAtExit);
|
|
miles.startup();
|
|
|
|
this->channels = configuration.mode == 1 ? 1 : 2;
|
|
|
|
switch (configuration.digitalRateType) {
|
|
case 0:
|
|
this->rate = 44100;
|
|
break;
|
|
case 1:
|
|
this->rate = 11025;
|
|
break;
|
|
case 2:
|
|
this->rate = 8000;
|
|
break;
|
|
default:
|
|
this->rate = 8000;
|
|
break;
|
|
}
|
|
|
|
switch (configuration.digitalBitsType) {
|
|
case 0:
|
|
this->bits = 16;
|
|
break;
|
|
case 1:
|
|
this->bits = 8;
|
|
break;
|
|
default:
|
|
this->bits = 8;
|
|
break;
|
|
}
|
|
|
|
miles.setPreference(15, configuration.preference15);
|
|
this->driver = miles.openDigitalDriver(this->rate, this->bits, this->channels, 1);
|
|
|
|
if (!this->driver) {
|
|
return false;
|
|
}
|
|
|
|
this->StopStreams();
|
|
|
|
if (configuration.mode == 1) {
|
|
for (int i = 0; i < this->sampleCount; ++i) {
|
|
this->samples[i] = miles.allocateSample(this->driver);
|
|
|
|
if (!this->samples[i]) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
if (configuration.mode != 2) {
|
|
return true;
|
|
}
|
|
|
|
strcpy_s(configuration.providerName, sizeof(configuration.providerName), "Miles Fast 2D Positional Audio");
|
|
|
|
int index = 0;
|
|
|
|
while (miles.enumerate3DProviders(&this->enumerator, &this->providers[index], &this->providerNames[index])) {
|
|
if (std::strcmp(this->providerNames[index], configuration.providerName) == 0) {
|
|
this->provider = this->providers[index];
|
|
break;
|
|
}
|
|
|
|
++index;
|
|
}
|
|
|
|
if (!this->provider) {
|
|
return true;
|
|
}
|
|
|
|
if (miles.open3DProvider(this->provider) != 0) {
|
|
return false;
|
|
}
|
|
|
|
if (miles.speakerType(this->provider) != -1) {
|
|
miles.setSpeakerType(this->provider, configuration.speakerType);
|
|
}
|
|
|
|
this->listener = miles.open3DListener(this->provider);
|
|
|
|
if (!this->listener) {
|
|
return false;
|
|
}
|
|
|
|
for (int i = 0; i < this->sample3DCount; ++i) {
|
|
this->samples3D[i] = miles.allocate3DSample(this->provider);
|
|
|
|
if (!this->samples3D[i]) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// OFFSET: 0x00639350
|
|
// FUNCTION: fn_04751
|
|
bool CSoundMgr::Create() {
|
|
if (g_soundMgr) {
|
|
return false;
|
|
}
|
|
|
|
g_soundMgr = new (std::nothrow) CSoundMgr();
|
|
|
|
if (!g_soundMgr) {
|
|
return false;
|
|
}
|
|
|
|
if (!g_soundMgr->initialized) {
|
|
delete g_soundMgr;
|
|
g_soundMgr = nullptr;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// OFFSET: 0x00639570
|
|
// FUNCTION: fn_04752
|
|
void CSoundMgr::Update() {
|
|
if (this->fadeThread != INVALID_HANDLE_VALUE) {
|
|
GetExitCodeThread(this->fadeThread, &this->fadeExit);
|
|
}
|
|
|
|
if (!this->fadePending || this->fadeExit != 0) {
|
|
return;
|
|
}
|
|
|
|
if (this->stream) {
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
miles.pauseStream(this->stream, 1);
|
|
miles.streamVolume(this->stream);
|
|
}
|
|
|
|
this->FadeIn();
|
|
this->RestartSecondary();
|
|
this->fadePending = 0;
|
|
}
|
|
|
|
// OFFSET: 0x006396B0
|
|
// FUNCTION: fn_45423
|
|
void CSoundMgr::Shutdown() {
|
|
if (g_soundConfiguration.mode == 0) {
|
|
return;
|
|
}
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
if (this->provider) {
|
|
for (void*& sample : this->samples3D) {
|
|
if (sample) {
|
|
miles.release3DSample(sample);
|
|
sample = nullptr;
|
|
}
|
|
}
|
|
|
|
miles.close3DListener(this->listener);
|
|
miles.close3DProvider(this->provider);
|
|
this->provider = 0;
|
|
}
|
|
|
|
this->StopStreams();
|
|
|
|
for (void*& sample : this->samples) {
|
|
if (sample) {
|
|
miles.releaseSample(sample);
|
|
sample = nullptr;
|
|
}
|
|
}
|
|
|
|
if (this->driver) {
|
|
miles.closeDigitalDriver(this->driver);
|
|
this->driver = nullptr;
|
|
}
|
|
|
|
miles.shutdown();
|
|
}
|
|
|
|
// OFFSET: 0x00639880
|
|
// FUNCTION: fn_04753
|
|
void CSoundMgr::Destroy() {
|
|
if (g_soundMgr) {
|
|
delete g_soundMgr;
|
|
g_soundMgr = nullptr;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x006398A0
|
|
// FUNCTION: fn_04754
|
|
void CSoundMgr::EndSamples() {
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
for (int i = 0; i < 48; ++i) {
|
|
if (this->samples[i]) {
|
|
miles.endSample(this->samples[i]);
|
|
}
|
|
}
|
|
|
|
if (this->provider) {
|
|
for (int i = 0; i < 48; ++i) {
|
|
if (this->samples3D[i]) {
|
|
miles.end3DSample(this->samples3D[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00639910
|
|
// FUNCTION: fn_04755
|
|
unsigned __stdcall CSoundMgr::FadeThread(void* direction) {
|
|
MSG message;
|
|
|
|
if (direction == reinterpret_cast<void*>(1)) {
|
|
for (int step = 1; step <= 1000; ++step) {
|
|
if (PeekMessageA(&message, nullptr, WM_USER, WM_USER, PM_NOREMOVE)) {
|
|
break;
|
|
}
|
|
|
|
CSoundMgr* sound = g_soundMgr;
|
|
const int volume = CSoundMgr::Volume(sound);
|
|
|
|
if (sound->targetVolume <= volume) {
|
|
break;
|
|
}
|
|
|
|
const int next = sound->streamVolume + 1;
|
|
CSoundMgr::SetVolume(sound, next);
|
|
Sleep(10);
|
|
}
|
|
} else {
|
|
for (int step = 1; step <= 1000; ++step) {
|
|
if (PeekMessageA(&message, nullptr, WM_USER, WM_USER, PM_NOREMOVE)) {
|
|
break;
|
|
}
|
|
|
|
CSoundMgr* sound = g_soundMgr;
|
|
|
|
if (!sound || sound->streamVolume <= 0) {
|
|
break;
|
|
}
|
|
|
|
const int next = sound->streamVolume - 1;
|
|
CSoundMgr::SetVolume(sound, next);
|
|
Sleep(10);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// OFFSET: 0x00639A60
|
|
// FUNCTION: fn_04756
|
|
int CSoundMgr::Volume(const CSoundMgr* sound) {
|
|
return sound ? sound->streamVolume : 0;
|
|
}
|
|
|
|
// OFFSET: 0x00639A70
|
|
// FUNCTION: fn_04757
|
|
bool CSoundMgr::IsComplete() const {
|
|
if (g_soundConfiguration.mode == 0 || !this->stream || !this->secondaryStream || this->fadeExit != 0) {
|
|
return false;
|
|
}
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
if (miles.streamStatus(this->secondaryStream) == 2) {
|
|
return true;
|
|
}
|
|
|
|
return miles.streamStatus(this->stream) == 2;
|
|
}
|
|
|
|
// OFFSET: 0x00639AC0
|
|
// FUNCTION: fn_04758
|
|
bool CSoundMgr::IsStopped() const {
|
|
return this->stream && MilesRuntime::Get().streamStatus(this->stream) == 8;
|
|
}
|
|
|
|
// OFFSET: 0x00639AE0
|
|
// FUNCTION: fn_04759
|
|
void CSoundMgr::Unused(int, int) {
|
|
}
|
|
|
|
// OFFSET: 0x00639AF0
|
|
// FUNCTION: fn_04760
|
|
void CSoundMgr::Pause(CSoundMgr* sound, int paused) {
|
|
if (!sound || !sound->stream) {
|
|
return;
|
|
}
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
miles.pauseStream(sound->stream, paused);
|
|
miles.streamVolume(sound->stream);
|
|
|
|
if (paused == 0) {
|
|
sound->currentName = sound->defaultName;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00639B50
|
|
// FUNCTION: fn_45424
|
|
bool CSoundMgr::PlayData3D(const void* data, const float& x, const float& y, const float& z, int maximumDistance, int minimumDistance, float scale) {
|
|
const float scaledVolume = static_cast<float>(this->volume3D) * scale;
|
|
const int volume = static_cast<int>(scaledVolume);
|
|
|
|
if (!this->provider) {
|
|
return this->PlayData2D(data, x, y, z, 250, 40, 1.0f);
|
|
}
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
for (int i = 0; i < this->sample3DCount; ++i) {
|
|
if (!this->samples3D[i]) {
|
|
continue;
|
|
}
|
|
|
|
if (miles.sample3DStatus(this->samples3D[i]) != 2) {
|
|
continue;
|
|
}
|
|
|
|
if (!miles.set3DSampleFile(this->samples3D[i], data)) {
|
|
return false;
|
|
}
|
|
|
|
miles.set3DSampleEffectsLevel(this->samples3D[i], this->effectsEnabled ? 1.0f : 0.0f);
|
|
miles.set3DPosition(this->samples3D[i], x, y, z);
|
|
miles.set3DOrientation(this->samples3D[i], -x, -y, -z, 0.0f, 1.0f, 0.0f);
|
|
miles.set3DSampleVolume(this->samples3D[i], volume);
|
|
miles.set3DSampleDistances(this->samples3D[i], static_cast<float>(maximumDistance), static_cast<float>(minimumDistance));
|
|
miles.start3DSample(this->samples3D[i]);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// OFFSET: 0x00639D30
|
|
// FUNCTION: fn_04761
|
|
void CSoundMgr::SetDefaultName(std::string name) {
|
|
this->defaultName = name;
|
|
|
|
if (g_serviceOptions.Get(7)) {
|
|
this->PlayStream(nullptr, 0, false);
|
|
}
|
|
|
|
this->SetRoom(0);
|
|
}
|
|
|
|
// OFFSET: 0x00639DF0
|
|
// FUNCTION: fn_04762
|
|
bool CSoundMgr::PlayData2D(const void* data, const float& x, const float& y, const float& z, int maximumDistance, int minimumDistance, float scale) {
|
|
const float zSquared = z * z;
|
|
const float xSquared = x * x;
|
|
const float horizontalSquared = xSquared + zSquared;
|
|
const float horizontal = SquareRoot(horizontalSquared);
|
|
const float horizontalResquared = horizontal * horizontal;
|
|
const float ySquared = y * y;
|
|
const float distanceSquared = ySquared + horizontalResquared;
|
|
const float distance = SquareRoot(distanceSquared);
|
|
|
|
if (distance >= static_cast<float>(maximumDistance)) {
|
|
return false;
|
|
}
|
|
|
|
int volume = this->sampleVolume;
|
|
const float minimum = static_cast<float>(minimumDistance);
|
|
|
|
if (!(minimum >= distance)) {
|
|
const float numerator = static_cast<float>(volume) * minimum;
|
|
const float attenuatedVolume = numerator / distance;
|
|
volume = static_cast<int>(attenuatedVolume);
|
|
}
|
|
|
|
const float scaledVolume = static_cast<float>(volume) * scale;
|
|
volume = static_cast<int>(scaledVolume);
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
for (int i = 0; i < this->sampleCount; ++i) {
|
|
if (!this->samples[i]) {
|
|
continue;
|
|
}
|
|
|
|
if (miles.sampleStatus(this->samples[i]) != 2) {
|
|
continue;
|
|
}
|
|
|
|
miles.initSample(this->samples[i]);
|
|
miles.setSampleFile(this->samples[i], data, 0);
|
|
miles.setSampleVolume(this->samples[i], volume);
|
|
miles.startSample(this->samples[i]);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// OFFSET: 0x00639F00
|
|
// FUNCTION: fn_04763
|
|
void CSoundMgr::PlayStream(const char* name, int loopCount, bool fade) {
|
|
if (g_soundConfiguration.mode == 0) {
|
|
return;
|
|
}
|
|
|
|
if (!name) {
|
|
name = this->defaultName.c_str();
|
|
}
|
|
|
|
if (this->currentName == name) {
|
|
return;
|
|
}
|
|
|
|
if (fade) {
|
|
this->FadeOut();
|
|
this->fadePending = 1;
|
|
this->currentName.assign(name);
|
|
|
|
if (this->secondaryStream) {
|
|
this->reopenPending = 1;
|
|
return;
|
|
}
|
|
|
|
this->secondaryStream = MilesRuntime::Get().openStream(this->driver, this->currentName.c_str(), 0);
|
|
const std::string copiedName(name);
|
|
return;
|
|
}
|
|
|
|
this->StopStreams();
|
|
this->currentName.assign(name);
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
this->stream = miles.openStream(this->driver, this->currentName.c_str(), 0);
|
|
|
|
{
|
|
const std::string copiedName(name);
|
|
}
|
|
|
|
miles.setStreamVolume(this->stream, this->streamVolume);
|
|
miles.setStreamLoopCount(this->stream, loopCount);
|
|
miles.startStream(this->stream);
|
|
}
|
|
|
|
// OFFSET: 0x0063A130
|
|
// FUNCTION: fn_04764
|
|
void CSoundMgr::PlayWave(const char* name, float x, float y, float z, int maximumDistance, int minimumDistance, float scale, int unused) {
|
|
const unsigned char enabled = g_serviceOptions.Get(11);
|
|
|
|
if (g_soundConfiguration.mode == 0 || !enabled) {
|
|
return;
|
|
}
|
|
|
|
static constexpr char permittedName[] = "버튼소리.wav";
|
|
|
|
if (this->tingOnly != 0 && std::strcmp(name, permittedName) != 0) {
|
|
return;
|
|
}
|
|
|
|
CWave* wave = static_cast<CWave*>(ResourceMgr::Instance().Load(name));
|
|
|
|
if (!wave) {
|
|
return;
|
|
}
|
|
|
|
if (g_soundConfiguration.mode == 1) {
|
|
this->PlayData2D(wave->data, x, y, z, maximumDistance, minimumDistance, scale);
|
|
} else if (g_soundConfiguration.mode == 2) {
|
|
this->PlayData3D(wave->data, x, y, z, maximumDistance, minimumDistance, scale);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x0063A3B0
|
|
// FUNCTION: fn_45425
|
|
void CSoundMgr::RestartSecondary() {
|
|
if (!this->secondaryEnabled) {
|
|
return;
|
|
}
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
if (this->reopenPending && this->secondaryStream) {
|
|
miles.closeStream(this->secondaryStream);
|
|
this->secondaryStream = nullptr;
|
|
this->secondaryStream = miles.openStream(this->driver, this->currentName.c_str(), 0);
|
|
this->reopenPending = 0;
|
|
}
|
|
|
|
if (this->secondaryStream) {
|
|
miles.setStreamVolume(this->secondaryStream, this->streamVolume);
|
|
miles.setStreamLoopCount(this->secondaryStream, 1);
|
|
miles.startStream(this->secondaryStream);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x0063A440
|
|
// FUNCTION: fn_04765
|
|
void CSoundMgr::SetSampleVolume(int volume) {
|
|
this->sampleVolume = volume > 127 ? 127 : (volume < 0 ? 0 : volume);
|
|
}
|
|
|
|
// OFFSET: 0x0063A470
|
|
// FUNCTION: fn_04766
|
|
void CSoundMgr::Set3DVolume(int volume) {
|
|
this->volume3D = volume > 127 ? 127 : (volume < 0 ? 0 : volume);
|
|
}
|
|
|
|
// OFFSET: 0x0063A4A0
|
|
// FUNCTION: fn_04767
|
|
void CSoundMgr::SetTargetVolume(int volume) {
|
|
this->targetVolume = volume > 127 ? 127 : (volume < 0 ? 0 : volume);
|
|
}
|
|
|
|
// OFFSET: 0x0063A4D0
|
|
// FUNCTION: fn_04768
|
|
void CSoundMgr::SetListenerYaw(float yaw) {
|
|
if (!this->listener) {
|
|
return;
|
|
}
|
|
|
|
const float angle = 180.0f - yaw;
|
|
const int degrees = static_cast<int>(angle);
|
|
const float sine = ClientSine(degrees);
|
|
const float cosine = ClientCosine(degrees);
|
|
MilesRuntime::Get().set3DOrientation(this->listener, sine, 0.0f, -cosine, 0.0f, 1.0f, 0.0f);
|
|
}
|
|
|
|
// OFFSET: 0x0063A560
|
|
// FUNCTION: fn_45426
|
|
void CSoundMgr::SetRoom(int room) {
|
|
if (!this->provider) {
|
|
return;
|
|
}
|
|
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
this->roomSupport = miles.roomType(this->provider) != -1;
|
|
|
|
if (this->roomSupport) {
|
|
miles.setRoomType(this->provider, room);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x0063A5A0
|
|
// FUNCTION: fn_04769
|
|
void CSoundMgr::SetVolume(CSoundMgr* sound, int volume) {
|
|
if (!sound) {
|
|
return;
|
|
}
|
|
|
|
sound->streamVolume = volume > 127 ? 127 : (volume < 0 ? 0 : volume);
|
|
MilesRuntime& miles = MilesRuntime::Get();
|
|
|
|
if (sound->stream) {
|
|
miles.setStreamVolume(sound->stream, sound->streamVolume);
|
|
}
|
|
|
|
if (sound->secondaryStream) {
|
|
miles.setStreamVolume(sound->secondaryStream, sound->streamVolume);
|
|
}
|
|
}
|