Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix audio plugin file extension #75

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 69 additions & 49 deletions cleo_plugins/Audio/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using namespace CLEO;
using namespace plugin;

#define VALIDATE_STREAM() if(!soundSystem.HasStream(stream)) { SHOW_ERROR("Invalid or already closed '0x%X' audio stream handle param in script %s \nScript suspended.", stream, ScriptInfoStr(thread).c_str()); return thread->Suspend(); }
#define VALIDATE_STREAM() if(stream != nullptr && !soundSystem.HasStream(stream)) { SHOW_ERROR("Invalid or already closed '0x%X' audio stream handle param in script %s \nScript suspended.", stream, ScriptInfoStr(thread).c_str()); return thread->Suspend(); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we also suspend when stream is nullptr?

if(stream == nullptr || !soundSystem.HasStream(stream))

Copy link
Collaborator Author

@MiranDMC MiranDMC Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy code allowed null ptr as input arg in sound stream opcodes.
These changes are dictated by actuall mod that happens to relay on it.

So now code allows 0 and any valid stream handle.


class Audio
{
Expand Down Expand Up @@ -106,7 +106,7 @@ class Audio
//0AAD=2,set_audiostream %1d% perform_action %2d%
static OpcodeResult __stdcall opcode_0AAD(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM(); VALIDATE_STREAM()
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM()
auto action = OPCODE_READ_PARAM_INT();

if (stream)
Expand All @@ -128,19 +128,20 @@ class Audio
//0AAE=1,release_audiostream %1d%
static OpcodeResult __stdcall opcode_0AAE(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

soundSystem.DestroyStream(stream);
if (stream) soundSystem.DestroyStream(stream);

return OR_CONTINUE;
}

//0AAF=2,%2d% = get_audiostream_length %1d%
static OpcodeResult __stdcall opcode_0AAF(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

auto length = stream->GetLength();
auto length = 0.0f;
if (stream) length = stream->GetLength();

OPCODE_WRITE_PARAM_INT((int)length);
return OR_CONTINUE;
Expand All @@ -149,9 +150,10 @@ class Audio
//0AB9=2,get_audio_stream_state %1d% store_to %2d%
static OpcodeResult __stdcall opcode_0AB9(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

auto state = stream->GetState();
auto state = CAudioStream::eStreamState::Stopped;
if (stream) state = stream->GetState();

OPCODE_WRITE_PARAM_INT(state);
return OR_CONTINUE;
Expand All @@ -160,9 +162,10 @@ class Audio
//0ABB=2,%2d% = get_audio_stream_volume %1d%
static OpcodeResult __stdcall opcode_0ABB(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

auto volume = stream->GetVolume();
auto volume = 0.0f;
if (stream) volume = stream->GetVolume();

OPCODE_WRITE_PARAM_FLOAT(volume);
return OR_CONTINUE;
Expand All @@ -171,21 +174,21 @@ class Audio
//0ABC=2,set_audiostream %1d% volume %2d%
static OpcodeResult __stdcall opcode_0ABC(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto volume = OPCODE_READ_PARAM_FLOAT();

stream->SetVolume(volume);
if (stream) stream->SetVolume(volume);

return OR_CONTINUE;
}

//0AC0=2,loop_audiostream %1d% flag %2d%
static OpcodeResult __stdcall opcode_0AC0(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto loop = OPCODE_READ_PARAM_BOOL();

stream->SetLooping(loop);
if (stream) stream->SetLooping(loop);

return OR_CONTINUE;
}
Expand All @@ -205,75 +208,90 @@ class Audio
//0AC2=4,set_3d_audiostream %1d% position %2d% %3d% %4d%
static OpcodeResult __stdcall opcode_0AC2(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
CVector pos;
pos.x = OPCODE_READ_PARAM_FLOAT();
pos.y = OPCODE_READ_PARAM_FLOAT();
pos.z = OPCODE_READ_PARAM_FLOAT();

stream->Set3dPosition(pos);
if (stream) stream->Set3dPosition(pos);

return OR_CONTINUE;
}

//0AC3=2,link_3d_audiostream %1d% to_object %2d%
static OpcodeResult __stdcall opcode_0AC3(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto handle = OPCODE_READ_PARAM_OBJECT_HANDLE();

auto object = CPools::GetObject(handle);
stream->Link(object);
if (stream)
{
auto object = CPools::GetObject(handle);
stream->Link(object);
}

return OR_CONTINUE;
}

//0AC4=2,link_3d_audiostream %1d% to_actor %2d%
static OpcodeResult __stdcall opcode_0AC4(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto handle = OPCODE_READ_PARAM_PED_HANDLE();

auto ped = CPools::GetPed(handle);
stream->Link(ped);
if (stream)
{
auto ped = CPools::GetPed(handle);
stream->Link(ped);
}

return OR_CONTINUE;
}

//0AC5=2,link_3d_audiostream %1d% to_vehicle %2d%
static OpcodeResult __stdcall opcode_0AC5(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto handle = OPCODE_READ_PARAM_VEHICLE_HANDLE();

auto vehicle = CPools::GetVehicle(handle);
stream->Link(vehicle);
if (stream)
{
auto vehicle = CPools::GetVehicle(handle);
stream->Link(vehicle);
}

return OR_CONTINUE;
}

//2500=1, is_audio_stream_playing %1d%
static OpcodeResult __stdcall opcode_2500(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

auto state = stream->GetState();
auto state = CAudioStream::eStreamState::Stopped;
if (stream) state = stream->GetState();

OPCODE_CONDITION_RESULT(state == 1);
OPCODE_CONDITION_RESULT(state == CAudioStream::eStreamState::Playing);
return OR_CONTINUE;
}

//2501=2,%2d% = get_audiostream_duration %1d%
static OpcodeResult __stdcall opcode_2501(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

auto length = stream->GetLength();
auto length = 0.0f;
if (stream)
{
auto length = stream->GetLength();

auto speed = stream->GetSpeed();
if (speed <= 0.0f)
length = FLT_MAX; // it would take forever to play paused
else
length /= speed; // speed corrected
auto speed = stream->GetSpeed();
if (speed <= 0.0f)
length = FLT_MAX; // it would take forever to play paused
else
length /= speed; // speed corrected
}

OPCODE_WRITE_PARAM_FLOAT(length);
return OR_CONTINUE;
Expand All @@ -282,9 +300,10 @@ class Audio
//2502=2,get_audio_stream_speed %1d% store_to %2d%
static OpcodeResult __stdcall opcode_2502(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

auto speed = stream->GetSpeed();
auto speed = 0.0f;
if (stream) speed = stream->GetSpeed();

OPCODE_WRITE_PARAM_FLOAT(speed);
return OR_CONTINUE;
Expand All @@ -293,55 +312,56 @@ class Audio
//2503=2,set_audio_stream_speed %1d% speed %2d%
static OpcodeResult __stdcall opcode_2503(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto speed = OPCODE_READ_PARAM_FLOAT();

stream->SetSpeed(speed);
if (stream) stream->SetSpeed(speed);

return OR_CONTINUE;
}

//2504=3,set_audio_stream_volume_with_transition %1d% volume %2d% time_ms %2d%
static OpcodeResult __stdcall opcode_2504(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto volume = OPCODE_READ_PARAM_FLOAT();
auto time = OPCODE_READ_PARAM_INT();

stream->SetVolume(volume, 0.001f * time);
if (stream) stream->SetVolume(volume, 0.001f * time);

return OR_CONTINUE;
}

//2505=3,set_audio_stream_speed_with_transition %1d% speed %2d% time_ms %2d%
static OpcodeResult __stdcall opcode_2505(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto speed = OPCODE_READ_PARAM_FLOAT();
auto time = OPCODE_READ_PARAM_INT();

stream->SetSpeed(speed, 0.001f * time);
if (stream) stream->SetSpeed(speed, 0.001f * time);

return OR_CONTINUE;
}

//2506=2,set_audio_stream_source_size %1d% radius %2d%
static OpcodeResult __stdcall opcode_2506(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto radius = OPCODE_READ_PARAM_FLOAT();

stream->Set3dSize(radius);
if (stream) stream->Set3dSize(radius);

return OR_CONTINUE;
}

//2507=2,get_audio_stream_progress %1d% store_to %2d%
static OpcodeResult __stdcall opcode_2507(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();

auto progress = stream->GetProgress();
auto progress = 0.0f;
if (stream) progress = stream->GetProgress();

OPCODE_WRITE_PARAM_FLOAT(progress);
return OR_CONTINUE;
Expand All @@ -350,10 +370,10 @@ class Audio
//2508=2,set_audio_stream_progress %1d% speed %2d%
static OpcodeResult __stdcall opcode_2508(CScriptThread* thread)
{
auto stream = (CAudioStream*)OPCODE_READ_PARAM_PTR(); VALIDATE_STREAM();
auto stream = (CAudioStream*)OPCODE_READ_PARAM_UINT(); VALIDATE_STREAM();
auto speed = OPCODE_READ_PARAM_FLOAT();

stream->SetProgress(speed);
if (stream) stream->SetProgress(speed);

return OR_CONTINUE;
}
Expand Down
4 changes: 2 additions & 2 deletions cleo_plugins/Audio/Audio.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>Audio</TargetName>
<TargetExt>.cleo5</TargetExt>
<TargetExt>.cleo</TargetExt>
<LibraryPath>$(ProjectDir)bass;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir).output\</OutDir>
<IntDir>$(ProjectDir).obj\$(Configuration)\</IntDir>
<TargetName>Audio</TargetName>
<TargetExt>.cleo5</TargetExt>
<TargetExt>.cleo</TargetExt>
<LibraryPath>$(ProjectDir)bass;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions cleo_plugins/Audio/CAudioStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ void CAudioStream::Stop()
{
BASS_ChannelPause(streamInternal);
state = Stopped;

// cancel ongoing transitions
speed = speedTarget;
volume = volumeTarget;
}

void CAudioStream::Resume()
Expand Down