Skip to content
Open
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
27 changes: 27 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PR Checks

on:
pull_request:

permissions:
contents: read

env:
DOTNET_NOLOGO: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true

jobs:
formatting:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x

- name: Verify whitespace formatting
run: dotnet format whitespace --verify-no-changes
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: CI
name: Release CI

on:
pull_request:
push:
branches:
- main
Expand Down Expand Up @@ -35,7 +34,6 @@ jobs:
run: dotnet format whitespace --verify-no-changes

build:
if: github.event_name != 'pull_request'
runs-on: windows-latest
needs: formatting
steps:
Expand Down
24 changes: 19 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<Deterministic>true</Deterministic>
Expand Down Expand Up @@ -70,7 +70,8 @@
<HintPath Condition="Exists('$(ResoniteManagedPath)FrooxEngine.dll')"
>$(ResoniteManagedPath)FrooxEngine.dll</HintPath
>
<HintPath Condition="!Exists('$(ResoniteManagedPath)FrooxEngine.dll') and Exists('$(ResonitePath)FrooxEngine.dll')"
<HintPath
Condition="!Exists('$(ResoniteManagedPath)FrooxEngine.dll') and Exists('$(ResonitePath)FrooxEngine.dll')"
>$(ResonitePath)FrooxEngine.dll</HintPath
>
<Private>false</Private>
Expand All @@ -79,7 +80,8 @@
<HintPath Condition="Exists('$(ResoniteManagedPath)Elements.Core.dll')"
>$(ResoniteManagedPath)Elements.Core.dll</HintPath
>
<HintPath Condition="!Exists('$(ResoniteManagedPath)Elements.Core.dll') and Exists('$(ResonitePath)Elements.Core.dll')"
<HintPath
Condition="!Exists('$(ResoniteManagedPath)Elements.Core.dll') and Exists('$(ResonitePath)Elements.Core.dll')"
>$(ResonitePath)Elements.Core.dll</HintPath
>
<Private>false</Private>
Expand All @@ -88,7 +90,8 @@
<HintPath Condition="Exists('$(ResoniteManagedPath)Elements.Assets.dll')"
>$(ResoniteManagedPath)Elements.Assets.dll</HintPath
>
<HintPath Condition="!Exists('$(ResoniteManagedPath)Elements.Assets.dll') and Exists('$(ResonitePath)Elements.Assets.dll')"
<HintPath
Condition="!Exists('$(ResoniteManagedPath)Elements.Assets.dll') and Exists('$(ResonitePath)Elements.Assets.dll')"
>$(ResonitePath)Elements.Assets.dll</HintPath
>
<Private>false</Private>
Expand All @@ -97,11 +100,22 @@
<HintPath Condition="Exists('$(ResoniteManagedPath)POpusCodec.dll')"
>$(ResoniteManagedPath)POpusCodec.dll</HintPath
>
<HintPath Condition="!Exists('$(ResoniteManagedPath)POpusCodec.dll') and Exists('$(ResonitePath)POpusCodec.dll')"
<HintPath
Condition="!Exists('$(ResoniteManagedPath)POpusCodec.dll') and Exists('$(ResonitePath)POpusCodec.dll')"
>$(ResonitePath)POpusCodec.dll</HintPath
>
<Private>false</Private>
</Reference>
<Reference Include="Awwdio">
<HintPath Condition="Exists('$(ResoniteManagedPath)Awwdio.dll')"
>$(ResoniteManagedPath)Awwdio.dll</HintPath
>
<HintPath
Condition="!Exists('$(ResoniteManagedPath)Awwdio.dll') and Exists('$(ResonitePath)Awwdio.dll')"
>$(ResonitePath)Awwdio.dll</HintPath
>
<Private>false</Private>
</Reference>
<Reference Include="ResoniteHotReloadLib" Condition="'$(Configuration)'=='Debug'">
<HintPath>$(ResoniteLibsPath)ResoniteHotReloadLib.dll</HintPath>
<Private>false</Private>
Expand Down
60 changes: 30 additions & 30 deletions TurboAudioStream.PrePatcher/TurboAudioStream.PrePatcher.csproj
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>NU1603</NoWarn>
</PropertyGroup>
<ItemGroup>
<!-- MonkeyLoader GamePack for Resonite (provides Shim assemblies) -->
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>NU1603</NoWarn>
</PropertyGroup>
<ItemGroup>
<!-- MonkeyLoader GamePack for Resonite (provides Shim assemblies) -->
<PackageReference Include="MonkeyLoader.GamePacks.Resonite" />

<!-- Direct references to actual Resonite assemblies for type resolution -->
<Reference Include="FrooxEngine">
<HintPath>$(ResoniteManagedPath)FrooxEngine.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Elements.Core">
<HintPath>$(ResoniteManagedPath)Elements.Core.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Elements.Assets">
<HintPath>$(ResoniteManagedPath)Elements.Assets.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="POpusCodec">
<HintPath>$(ResoniteManagedPath)POpusCodec.dll</HintPath>
<Private>false</Private>
</Reference>
<!-- Direct references to actual Resonite assemblies for type resolution -->
<Reference Include="FrooxEngine">
<HintPath>$(ResoniteManagedPath)FrooxEngine.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Elements.Core">
<HintPath>$(ResoniteManagedPath)Elements.Core.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="Elements.Assets">
<HintPath>$(ResoniteManagedPath)Elements.Assets.dll</HintPath>
<Private>false</Private>
</Reference>
<Reference Include="POpusCodec">
<HintPath>$(ResoniteManagedPath)POpusCodec.dll</HintPath>
<Private>false</Private>
</Reference>

<!-- Update pattern for any other Resonite assemblies -->
<Reference Update="Resonite.*">
<HintPath>$(ResoniteManagedPath)%(Filename).dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
<!-- Update pattern for any other Resonite assemblies -->
<Reference Update="Resonite.*">
<HintPath>$(ResoniteManagedPath)%(Filename).dll</HintPath>
<Private>false</Private>
</Reference>
</ItemGroup>
</Project>
5 changes: 4 additions & 1 deletion TurboAudioStream/AudioBindingRepairHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ out AudioStreamController? controller
repaired = true;
}

if (source is OpusStream<StereoSample> opusStream && audioStreamInterface.Bitrate.Target is null)
if (
source is OpusStream<StereoSample> opusStream
&& audioStreamInterface.Bitrate.Target is null
)
{
audioStreamInterface.Bitrate.Target = opusStream.BitRate;
repaired = true;
Expand Down
6 changes: 3 additions & 3 deletions TurboAudioStream/AudioPatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public static void Synchronize()
{
foreach (Type patchType in registration.PatchTypes)
{
registration.Harmony.CreateClassProcessor(patchType).Patch();
_ = registration.Harmony.CreateClassProcessor(patchType).Patch();
}

registration.IsPatched = true;
}
else if (!shouldBeEnabled && registration.IsPatched)
{
registration.Harmony.UnpatchSelf();
registration.Harmony.UnpatchAll(registration.Harmony.Id);
registration.IsPatched = false;
}
}
Expand All @@ -79,7 +79,7 @@ public static void UnpatchAll()
{
foreach ((_, PatchRegistration registration) in Registrations)
{
registration.Harmony.UnpatchSelf();
registration.Harmony.UnpatchAll(registration.Harmony.Id);
registration.IsPatched = false;
}
}
Expand Down
7 changes: 5 additions & 2 deletions TurboAudioStream/AudioPatchPredicates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ namespace TurboAudioStream;

internal static class AudioPatchPredicates
{
public static bool IsLocalSenderOpusStream(IAudioStream source, out OpusStream<StereoSample>? stream)
public static bool IsLocalSenderOpusStream(
IAudioStream source,
out OpusStream<StereoSample>? stream
)
{
stream = source as OpusStream<StereoSample>;
return stream?.User?.IsLocalUser == true;
Expand All @@ -17,6 +20,6 @@ out OpusStream<StereoSample>? opusStream
)
{
opusStream = stream as OpusStream<StereoSample>;
return opusStream?.User?.IsLocalUser != true;
return opusStream is not null && opusStream.User?.IsLocalUser != true;
}
}
6 changes: 1 addition & 5 deletions TurboAudioStream/PatchTriggerLogger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Concurrent;
using Elements.Core;
using FrooxEngine;
using ResoniteModLoader;

Expand Down Expand Up @@ -34,10 +33,7 @@ public static void Log(
Math.Max(0f, TurboAudioStreamConfig.PatchLogCooldownSeconds)
);

if (
LastLogTimes.TryGetValue(key, out DateTime lastLogTime)
&& now - lastLogTime < cooldown
)
if (LastLogTimes.TryGetValue(key, out DateTime lastLogTime) && now - lastLogTime < cooldown)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Elements.Assets;
using FrooxEngine;
using HarmonyLib;

Expand All @@ -20,17 +19,23 @@ bool spatialize
return;
}

if (!AudioBindingRepairHelper.TryRepair(__instance, source, out AudioStreamController? controller))
if (
!AudioBindingRepairHelper.TryRepair(
__instance,
source,
out AudioStreamController? controller
)
)
{
return;
}

User? user = (source as IAudioStream)?.User;
User? user = source.User;
PatchTriggerLogger.Log(
AudioPatchFeature.BindRepair,
$"repaired-interface-bind bitrate={bitrate} volume={volume:0.###} spatialize={spatialize}",
user,
source as IWorldElement,
source,
controller?.Slot
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public static void Prefix(IAudioStream source)
{
try
{
if (!AudioPatchPredicates.IsLocalSenderOpusStream(source, out OpusStream<StereoSample>? stream))
if (
!AudioPatchPredicates.IsLocalSenderOpusStream(
source,
out OpusStream<StereoSample>? stream
)
)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@

namespace TurboAudioStream.Patches;

[HarmonyPatch]
internal static class AudioStreamStereoSample_Read_ReceiverHeadroom_Patch
{
private static MethodBase TargetMethod()
private static readonly Action<AudioStream<StereoSample>, int> UpdateReadSampleCount =
AccessTools.MethodDelegate<Action<AudioStream<StereoSample>, int>>(
AccessTools.DeclaredMethod(typeof(AudioStream<StereoSample>), "UpdateReadSampleCount")
?? throw new MissingMethodException(
typeof(AudioStream<StereoSample>).FullName,
"UpdateReadSampleCount"
)
);

[HarmonyTargetMethod]
internal static MethodInfo TargetMethod()
{
Type closedType = typeof(AudioStream<>).MakeGenericType(typeof(StereoSample));
MethodInfo method = closedType
Expand All @@ -34,15 +45,22 @@ public static bool Prefix(
ref int ____missedSamples
)
{
if (!AudioPatchPredicates.IsRemoteReceiverOpusStream(__instance, out OpusStream<StereoSample>? opusStream))
_ = simulator;

if (
!AudioPatchPredicates.IsRemoteReceiverOpusStream(
__instance,
out OpusStream<StereoSample>? opusStream
)
)
{
return true;
}

Engine? engine = __instance.Engine;
if (__instance.IsDisposed || engine is null || __instance.User.IsAudioLocallyBlocked)
{
buffer.Fill(default);
buffer.Clear();
return false;
}

Expand All @@ -63,18 +81,19 @@ ref int ____missedSamples
{
if (___audioBuffer == null || ___audioBuffer.Length != effectiveTargetBufferSize)
{
___audioBuffer = new CircularAudioBuffer<StereoSample>(
effectiveTargetBufferSize,
___audioBuffer
);
___audioBuffer = ___audioBuffer is null
? new CircularAudioBuffer<StereoSample>(effectiveTargetBufferSize)
: new CircularAudioBuffer<StereoSample>(
effectiveTargetBufferSize,
___audioBuffer
);
}

double dspTime = engine.AudioSystem.DSPTime;
int effectiveMinimumBufferedSamples = MathX.RoundToInt(
sampleRate * effectiveMinimumBufferDelay
);
bool isNewFrame = ____lastAudioTime != dspTime;
double elapsedSeconds = ____lastAudioTime >= 0.0 ? dspTime - ____lastAudioTime : -1.0;
____lastAudioTime = dspTime;

if (isNewFrame)
Expand All @@ -96,9 +115,9 @@ ref int ____missedSamples

if (____activeReading || hasEnoughBufferedSamples)
{
__instance.UpdateReadSampleCount(buffer.Length);
UpdateReadSampleCount(__instance, buffer.Length);
int readSamples = ___audioBuffer.Read(buffer, ref globalPosition);
buffer.Slice(readSamples).Fill(default);
buffer[readSamples..].Clear();
____missedSamples += buffer.Length - readSamples;
____lastReadSamples = readSamples;

Expand All @@ -109,7 +128,7 @@ ref int ____missedSamples
}
else
{
buffer.Fill(default);
buffer.Clear();
}

if (!hasEnoughBufferedSamples)
Expand Down
Loading
Loading