Skip to content

Commit

Permalink
Restored legacy offset of CAudioStream::streamInternal
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranDMC committed Oct 12, 2024
1 parent bfe0954 commit 661e8f8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
3 changes: 3 additions & 0 deletions cleo_plugins/Audio/C3DAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ using namespace CLEO;

C3DAudioStream::C3DAudioStream(const char* filepath) : CAudioStream()
{
// see https://github.com/cleolibrary/CLEO5/pull/230
static_assert(offsetof(C3DAudioStream, streamInternal) == 4 && alignof(C3DAudioStream) == 4, "C3DAudioStream compatibility with CLEO4 broken!");

if (isNetworkSource(filepath) && !CSoundSystem::allowNetworkSources)
{
TRACE("Loading of 3d-audiostream '%s' failed. Support of network sources was disabled in SA.Audio.ini", filepath);
Expand Down
15 changes: 9 additions & 6 deletions cleo_plugins/Audio/CAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ using namespace CLEO;

CAudioStream::CAudioStream(const char* filepath)
{
// see https://github.com/cleolibrary/CLEO5/pull/230
static_assert(offsetof(CAudioStream, streamInternal) == 4 && alignof(CAudioStream) == 4, "CAudioStream compatibility with CLEO4 broken!");

if (isNetworkSource(filepath) && !CSoundSystem::allowNetworkSources)
{
TRACE("Loading of audiostream '%s' failed. Support of network sources was disabled in SA.Audio.ini", filepath);
Expand Down Expand Up @@ -111,7 +114,7 @@ void CAudioStream::SetVolume(float value, float transitionTime)
if (transitionTime <= 0.0)
volume = value; // instant
else
volumeTransitionStep = (volumeTarget - volume) / (1000.0 * transitionTime);
volumeTransitionStep = (volumeTarget - volume) / (1000.0f * transitionTime);
}

float CAudioStream::GetVolume() const
Expand All @@ -129,7 +132,7 @@ void CAudioStream::SetSpeed(float value, float transitionTime)
if (transitionTime <= 0.0)
speed = value; // instant
else
speedTransitionStep = (speedTarget - speed) / (1000.0 * transitionTime);
speedTransitionStep = (speedTarget - speed) / (1000.0f * transitionTime);
}

float CAudioStream::GetSpeed() const
Expand Down Expand Up @@ -161,11 +164,11 @@ void CAudioStream::UpdateVolume()
if (volume != volumeTarget)
{
auto timeDelta = CTimer::m_snTimeInMillisecondsNonClipped - CTimer::m_snPreviousTimeInMillisecondsNonClipped;
volume += volumeTransitionStep * (double)timeDelta; // animate the transition
volume += volumeTransitionStep * (float)timeDelta; // animate the transition

// check progress
auto remaining = volumeTarget - volume;
remaining *= (volumeTransitionStep > 0.0) ? 1.0 : -1.0;
remaining *= (volumeTransitionStep > 0.0f) ? 1.0f : -1.0f;
if (remaining < 0.0) // overshoot
{
volume = volumeTarget;
Expand All @@ -188,11 +191,11 @@ void CAudioStream::UpdateSpeed()
if (speed != speedTarget)
{
auto timeDelta = CTimer::m_snTimeInMillisecondsNonClipped - CTimer::m_snPreviousTimeInMillisecondsNonClipped;
speed += speedTransitionStep * (double)timeDelta; // animate the transition
speed += speedTransitionStep * (float)timeDelta; // animate the transition

// check progress
auto remaining = speedTarget - speed;
remaining *= (speedTransitionStep > 0.0) ? 1.0 : -1.0;
remaining *= (speedTransitionStep > 0.0f) ? 1.0f : -1.0f;
if (remaining < 0.0) // overshoot
{
speed = speedTarget; // done
Expand Down
12 changes: 6 additions & 6 deletions cleo_plugins/Audio/CAudioStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ namespace CLEO
eStreamType type = eStreamType::SoundEffect;
bool ok = false;
float rate = 44100.0f; // file's sampling rate
double speed = 1.0f;
double volume = 1.0f;
float speed = 1.0f;
float volume = 1.0f;

// transitions
double volumeTarget = 1.0f;
double volumeTransitionStep = 1.0f;
double speedTarget = 1.0f;
double speedTransitionStep = 1.0f;
float volumeTarget = 1.0f;
float volumeTransitionStep = 1.0f;
float speedTarget = 1.0f;
float speedTransitionStep = 1.0f;

CAudioStream() = default;
CAudioStream(const CAudioStream&) = delete; // no copying!
Expand Down
2 changes: 1 addition & 1 deletion cleo_sdk/CLEO.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ void WINAPI CLEO_RemoveScriptDeleteDelegate(FuncScriptDeleteDelegateT func);

DWORD WINAPI CLEO_GetScriptTextureById(CRunningScript* thread, int id); // ret RwTexture *

DWORD WINAPI CLEO_GetInternalAudioStream(CRunningScript* thread, DWORD stream); // arg CAudioStream *
DWORD WINAPI CLEO_GetInternalAudioStream(CRunningScript* unused, DWORD audioStreamPtr); // CAudioStream*

struct StringList { DWORD count; char** strings; };
void WINAPI CLEO_StringListFree(StringList list); // releases resources used by StringList container
Expand Down
4 changes: 2 additions & 2 deletions source/CleoBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ namespace CLEO
GetInstance().RemoveCallback(id, func);
}

DWORD WINAPI CLEO_GetInternalAudioStream(CLEO::CRunningScript* thread, DWORD stream) // arg CAudioStream *
DWORD WINAPI CLEO_GetInternalAudioStream(CLEO::CRunningScript* unused, DWORD audioStreamPtr)
{
return stream; // CAudioStream::streamInternal offset is 0
return *(DWORD*)(audioStreamPtr + 0x4); // CAudioStream->streamInternal
}

void WINAPI CLEO_ResolvePath(CLEO::CRunningScript* thread, char* inOutPath, DWORD pathMaxLen)
Expand Down

0 comments on commit 661e8f8

Please sign in to comment.