rodecomp/Source/Contents/Sound/SoundMaker.cpp
ragnarok-clanker 46d4abaff3 Decompile 2 functions in Source/Contents/Sound/SoundMaker.cpp
Batch #2167 by ragnarok-clanker: 0 byte-identical, 2 confirmed by peer review.

- fn_22400 CHalluNPC::OnProcess: logic confirmed by peer review
- fn_22402 CHalluPC::OnProcess: logic confirmed by peer review

Peer-reviewed-by: ntrl
Reviewed-by: ragnarok-clanker
2026-10-29 15:06:11 +00:00

537 lines
14 KiB
C++

#include "Contents/Sound/SoundMaker.h"
#include "Contents/Actors/EffectActors.h"
#include "Contents/Actors/GndRiser.h"
#include "Contents/Actors/Npc.h"
#include "Contents/Actors/Pc.h"
#include "Contents/Sound/SoundMgr.h"
#include "Client/Mode/ModeMgr.h"
#include "Client/Mode/CGameMode.h"
#include "Contents/World/World.h"
#include "UI/Window/UIWindowMgr.h"
#include "Resource/World/WorldResource.h"
#include "Utility/Math/AffineMatrix.h"
#include "Utility/Math/ScalarConversion.h"
#include <cmath>
#include <windows.h>
#include <timeapi.h>
// OFFSET: 0x00DA1190
// FUNCTION: fn_22354
CCorpse::CCorpse() {
this->render.visible = 1;
this->render.isLieOnGround = true;
this->spriteOffset = 0.0f;
this->render.unknown_008C = timeGetTime();
}
// OFFSET: 0x00DA1E30
// FUNCTION: fn_22363
CSoundMaker::CSoundMaker() {
this->file.clear();
this->volume = 100.0f;
this->range = 1.0f;
this->width = 3;
this->height = 3;
this->radius = SquareRoot(18.0f);
this->lastTick = timeGetTime() - 4000u;
}
// OFFSET: 0x00DA2220
// FUNCTION: fn_22364
CNpc::~CNpc() {
if (this->unknown_042C) {
g_windowMgr.Schedule(this->unknown_042C);
this->unknown_042C = nullptr;
}
if (this->unknown_0430) {
g_windowMgr.Schedule(this->unknown_0430);
this->unknown_0430 = nullptr;
}
}
CBlowEffect::~CBlowEffect() = default;
CBlurPC::~CBlurPC() = default;
CHalluNPC::~CHalluNPC() = default;
CHalluPC2::~CHalluPC2() = default;
CHalluPC::~CHalluPC() = default;
CHalluPlant::~CHalluPlant() = default;
CSoundMaker::~CSoundMaker() = default;
CCorpse::~CCorpse() = default;
CMasterChaser::~CMasterChaser() = default;
CNumEffect::~CNumEffect() = default;
// OFFSET: 0x00DA3340
// FUNCTION: fn_22403
bool CHalluPlant::OnProcess() {
return ++this->unknown_0440 <= 60;
}
// OFFSET: 0x00DA3980
// FUNCTION: fn_22405
bool CNumEffect::OnProcess() {
const float elapsed = static_cast<float>((timeGetTime() - this->render.unknown_008C) / 24.0);
this->render.previousAnimation = this->render.animation;
this->render.position.y = this->baseHeight - elapsed * 0.18f;
this->SetColor(static_cast<int>(255.0f - (elapsed + elapsed)), -1, -1, -1);
if (this->render.scale > 1.0f) {
this->render.scale = this->baseScale - elapsed * 0.24f;
} else if (this->render.scale < 1.0f) {
this->render.scale = 1.0f;
}
return elapsed <= 120.0f;
}
// OFFSET: 0x00DA3A60
// FUNCTION: fn_22406
bool CSoundMaker::OnProcess() {
if (this->width == 0) {
return true;
}
const auto* player = reinterpret_cast<const CRenderObject*>(static_cast<CGameMode*>(g_modeMgr.GetGameMode())->scene->player);
if (!player) {
return true;
}
const float distance = this->CalcDist(player->render.position.x, player->render.position.z);
if (distance - (this->radius + this->range) > 130.0f) {
return true;
}
const float deltaX = player->render.position.x - this->render.position.x;
const float deltaZ = player->render.position.z - this->render.position.z;
float signX = 1.0f;
float signZ = 1.0f;
if (deltaX < 0.0f && deltaZ >= 0.0f) {
signX = -1.0f;
} else if (deltaX < 0.0f && deltaZ < 0.0f) {
signX = -1.0f;
signZ = -1.0f;
} else if (deltaX >= 0.0f && deltaZ < 0.0f) {
signZ = -1.0f;
}
const float slope = deltaZ / std::fmax(deltaX, 0.001f);
float offsetX;
float offsetZ;
if (!(static_cast<float>(this->height / this->width) >= std::fabs(slope))) {
offsetZ = static_cast<float>(this->height) * signZ * 0.5f;
offsetX = offsetZ / std::fmax(slope, 0.001f);
} else {
offsetX = static_cast<float>(this->width) * signX * 0.5f;
offsetZ = slope * offsetX;
}
const float x = this->render.position.x + offsetX;
const float z = this->render.position.z + offsetZ;
if (player->CalcDist(x, z) - this->range > 75.0f || this->file.empty()) {
return true;
}
if (timeGetTime() > this->lastTick + this->cycle) {
this->lastTick = timeGetTime();
g_soundMgr->PlayWave(
this->file.c_str(), x - player->render.position.x, 0.0f, z - player->render.position.z, TruncateToInt(this->range),
TruncateToInt(this->range / 6.0f), this->volume, 0
);
}
return true;
}
// OFFSET: 0x00DA2AF0
// FUNCTION: fn_22378
int CPc::Slot46() {
return this->unknown_04D0;
}
// OFFSET: 0x00DA2B00
// FUNCTION: fn_22379
float* CPc::GetExtent(float* extent) const {
extent[0] = this->unknown_04EC - this->unknown_04E4;
extent[1] = this->unknown_04F0 - this->unknown_04E8;
return extent;
}
// OFFSET: 0x00DA2FA0
// FUNCTION: fn_22397
bool CBlurPC::OnProcess() {
CWorld* scene = static_cast<CGameMode*>(g_modeMgr.GetGameMode())->scene;
if (scene) {
const CRenderObject* owner = scene->GetGameActorByAidIncludeMe(this->render.accountId);
if (owner && (owner->render.flags & 0x10) != 0) {
this->render.flags = 0x10;
this->render.pulsePhases[0] = 45;
}
}
if (this->render.color < static_cast<std::uint32_t>(this->unknown_04FC)) {
return false;
}
this->render.color -= this->unknown_04FC;
return true;
}
// OFFSET: 0x00DA3240
// FUNCTION: fn_22401
bool CHalluPC2::OnProcess() {
CWorld* scene = static_cast<CGameMode*>(g_modeMgr.GetGameMode())->scene;
if (scene) {
const CRenderObject* owner = scene->GetGameActorByAidIncludeMe(this->render.accountId);
if (owner && (owner->render.flags & 0x10) != 0) {
this->render.flags = 0x10;
this->render.pulsePhases[0] = 45;
}
}
++this->unknown_050C;
if (this->render.color < static_cast<std::uint32_t>(this->unknown_04FC)) {
return false;
}
this->render.color -= this->unknown_04FC;
return true;
}
// OFFSET: 0x00DA4100
// FUNCTION: fn_22410
void CCorpse::Render(int argument) {
if (this->render.visible) {
this->DrawShadow(argument, this->render.scale);
this->DrawSprite(argument, false, this->spriteOffset);
}
}
// OFFSET: 0x00DA44B0
// FUNCTION: fn_22415
void CHalluPlant::Render(int argument) {
this->DrawSprite(argument, true, 0.0f);
}
// OFFSET: 0x00DA2B40
// FUNCTION: fn_22380
bool CPc::Slot58() {
return this->unknown_04E0;
}
// OFFSET: 0x00DA2B50
// FUNCTION: fn_22381
int CPc::Slot56() {
return this->unknown_04DC;
}
// OFFSET: 0x00DA2B60
// FUNCTION: fn_22382
int CPc::Slot42() {
return this->unknown_04CC;
}
// OFFSET: 0x00DA2B70
// FUNCTION: fn_22383
std::int64_t CPc::Slot35() {
return (static_cast<std::int64_t>(this->unknown_044C) << 32) | static_cast<std::uint32_t>(this->weapon);
}
// OFFSET: 0x00DA5800
// FUNCTION: fn_22429
void CPc::Slot59(bool value) {
this->unknown_04E0 = value;
}
// OFFSET: 0x00DA5810
// FUNCTION: fn_22430
void CPc::Slot57(int value) {
this->unknown_04DC = value;
}
// OFFSET: 0x00DA4150
// FUNCTION: fn_22411
void CGndRiser::Render(int) {
}
// OFFSET: 0x00DA4960
// FUNCTION: fn_22417
void CSoundMaker::Render(int) {
}
// OFFSET: 0x00DA4970
// FUNCTION: fn_22418
void CBlowEffect::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (message != 14 || a != 0) {
CRenderObject::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
return;
}
const float* position = reinterpret_cast<const float*>(b);
this->render.position.x = position[0];
this->render.position.y = position[1];
this->render.position.z = position[2];
this->render.visible = 1;
this->render.color = (d | e) ? 0xFFFF0000u : 0xFFFFFFFFu;
this->render.unknown_008C = timeGetTime();
}
// OFFSET: 0x00DA4A00
// FUNCTION: fn_22419
void CBlurPC::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (a != 0) {
CPc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
return;
}
switch (message) {
case 0:
this->SetColor(180, b, d, f);
this->unknown_04FC = 0x8000000;
break;
case 1:
this->render.color &= (b << 24) + 0xFFFFFF;
this->unknown_04FC = d << 24;
break;
case 2:
this->unknown_04F8 = *reinterpret_cast<const float*>(&b);
break;
case 3:
this->render.isMotionFreezed = 1;
break;
default:
CPc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
break;
}
}
// OFFSET: 0x00DA4AD0
// FUNCTION: fn_22420
void CCorpse::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
CRenderObject::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
}
// OFFSET: 0x00DA4BF0
// FUNCTION: fn_22422
void CHalluNPC::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (a != 0) {
CNpc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
return;
}
switch (message) {
case 0:
this->SetColor(180, b, d, f);
this->unknown_0444 = 0x8000000;
break;
case 1:
this->render.color &= (b << 24) + 0xFFFFFF;
this->unknown_0444 = d << 24;
break;
case 2:
this->unknown_0440 = *reinterpret_cast<const float*>(&b);
break;
case 3:
this->render.isMotionFreezed = 1;
break;
default:
CNpc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
break;
}
}
// OFFSET: 0x00DA4CC0
// FUNCTION: fn_22423
void CHalluPC2::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (a != 0) {
CPc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
return;
}
switch (message) {
case 0:
this->SetColor(180, 255, 55, 55);
this->unknown_04FC = 0x8000000;
break;
case 1:
this->render.color &= (b << 24) + 0xFFFFFF;
this->unknown_04FC = d << 24;
break;
case 2:
this->unknown_04F8 = *reinterpret_cast<const float*>(&b);
break;
case 3:
this->render.isMotionFreezed = 1;
break;
default:
CPc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
break;
}
}
// OFFSET: 0x00DA4D90
// FUNCTION: fn_22424
void CHalluPC::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (a != 0) {
CPc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
return;
}
switch (message) {
case 0:
this->SetColor(180, b, d, f);
this->unknown_04FC = 0x8000000;
break;
case 1:
this->render.color &= (b << 24) + 0xFFFFFF;
this->unknown_04FC = d << 24;
break;
case 2:
this->unknown_04F8 = *reinterpret_cast<const float*>(&b);
break;
case 3:
this->render.isMotionFreezed = 1;
break;
default:
CPc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
break;
}
}
// OFFSET: 0x00DA4E60
// FUNCTION: fn_22425
void CHalluPlant::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (a != 0) {
CNpc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
return;
}
switch (message) {
case 0:
this->SetColor(180, b, d, f);
break;
case 1:
this->render.color &= (b << 24) + 0xFFFFFF;
break;
case 3:
this->render.isMotionFreezed = 1;
break;
default:
CNpc::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
break;
}
}
// OFFSET: 0x00DA5610
// FUNCTION: fn_22427
void CNumEffect::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (message == 14 && a == 0) {
const float* position = reinterpret_cast<const float*>(b);
this->render.position.x = position[0];
this->render.position.y = position[1];
this->render.position.z = position[2];
this->render.visible = 1;
this->render.position.y -= 12.0f;
this->baseHeight = this->render.position.y;
this->render.curMotion = d;
if (d > 9 || d < 0) {
this->render.curMotion = 0;
}
this->render.unknown_0078 = f;
this->render.scale = 5.0f;
this->baseScale = 5.0f;
this->render.unknown_008C = timeGetTime();
return;
}
if (message == 22 && a == 0) {
return;
}
CRenderObject::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
}
// OFFSET: 0x00DA56E0
// FUNCTION: fn_22428
void CSoundMaker::SendMsg(
CGameObject* sender, int message, int a, int b, int c, int d, int e, int f, int g, int h, int i, int, int, int, int
) {
if (message != 14 || a != 0) {
CRenderObject::SendMsg(sender, message, a, b, c, d, e, f, g, h, i, 0, 0, 0, 0);
return;
}
const WorldSoundRecord& sound = *reinterpret_cast<const WorldSoundRecord*>(b);
this->file = sound.file;
this->volume = sound.volume;
this->width = sound.width;
this->height = sound.height;
this->range = sound.range;
this->render.position.x = sound.position[0];
this->render.position.y = sound.position[1];
this->render.position.z = sound.position[2];
this->radius = SquareRoot(static_cast<float>(this->width * this->width + this->height * this->height));
this->cycle = static_cast<std::int64_t>(sound.cycle * 1000.0f);
this->lastTick = timeGetTime() - this->cycle;
}
// OFFSET: 0x00DA31B0
// FUNCTION: fn_22400
bool CHalluNPC::OnProcess() {
const unsigned count = ++this->unknown_0454;
if (this->render.color < static_cast<std::uint32_t>(this->unknown_0444)) {
return false;
}
if (count == 110) {
static_cast<EffectActor*>(static_cast<CRenderObject*>(this))->LaunchEffect(793, vector3d{0.0f, 0.0f, 0.0f}, 0.0f);
}
if (count > 105 && (count & 3) == 0) {
this->render.color -= this->unknown_0444;
}
return true;
}
// OFFSET: 0x00DA32B0
// FUNCTION: fn_22402
bool CHalluPC::OnProcess() {
const unsigned count = ++this->unknown_050C;
if (this->render.color < static_cast<std::uint32_t>(this->unknown_04FC)) {
return false;
}
if (count == 110) {
static_cast<EffectActor*>(static_cast<CRenderObject*>(this))->LaunchEffect(793, vector3d{0.0f, 0.0f, 0.0f}, 0.0f);
}
if (count > 105 && (count & 3) == 0) {
this->render.color -= this->unknown_04FC;
}
return true;
}