Skip to content

Commit

Permalink
V5.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
hardcpp committed Mar 3, 2023
1 parent d020eff commit 3c1fb5d
Show file tree
Hide file tree
Showing 51 changed files with 8,569 additions and 43 deletions.
36 changes: 34 additions & 2 deletions BeatSaberPlus/BeatSaberPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;CP_SDK_IPA;CP_SDK_UNITY</DefineConstants>
<DefineConstants>TRACE;DEBUG;CP_SDK_IPA;CP_SDK_UNITY;UNITY_5_3_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2019_1_OR_NEWER UNITY_STANDALONE_WIN;UNITY_2018_3_OR_NEWER;NETSTANDARD</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>CP_SDK_IPA;CP_SDK_UNITY</DefineConstants>
<DefineConstants>CP_SDK_IPA;CP_SDK_UNITY;UNITY_5_3_OR_NEWER;UNITY_2018_2_OR_NEWER;UNITY_2019_1_OR_NEWER UNITY_STANDALONE_WIN;UNITY_2018_3_OR_NEWER;NETSTANDARD</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
Expand Down Expand Up @@ -117,6 +117,11 @@
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\System.IO.Compression.FileSystem.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System.Runtime.Serialization">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\System.Runtime.Serialization.dll</HintPath>
<Private>False</Private>
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\System.Web.dll</HintPath>
<Private>False</Private>
Expand Down Expand Up @@ -237,6 +242,33 @@
<Compile Include="CP_SDK\ModuleBase.cs" />
<Compile Include="CP_SDK\Network\APIClient.cs" />
<Compile Include="CP_SDK\Network\APIResponse.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\BaseChannel.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\ConnectionRequest.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\INetEventListener.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Layers\Crc32cLayer.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Layers\PacketLayerBase.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Layers\XorEncryptLayer.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NatPunchModule.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetConstants.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetDebug.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetManager.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetPacket.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetPacketPool.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetPeer.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetSocket.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetStatistics.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\NetUtils.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\ReliableChannel.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\SequencedChannel.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\CRC32C.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\FastBitConverter.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\INetSerializable.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NetDataReader.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NetDataWriter.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NetPacketProcessor.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NetSerializer.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NtpPacket.cs" />
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NtpRequest.cs" />
<Compile Include="CP_SDK\Network\RateLimitInfo.cs" />
<Compile Include="CP_SDK\Network\WebClient_Unity.cs" />
<Compile Include="CP_SDK\Network\WebResponse.cs" />
Expand Down
Binary file modified BeatSaberPlus/BeatSaberPlus.csproj.user
Binary file not shown.
52 changes: 52 additions & 0 deletions BeatSaberPlus/CP_SDK/Network/LiteNetLib/BaseChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.Threading;

namespace CP_SDK_LiteNetLib
{
internal abstract class BaseChannel
{
protected readonly NetPeer Peer;
protected readonly Queue<NetPacket> OutgoingQueue;
private int _isAddedToPeerChannelSendQueue;

public int PacketsInQueue
{
get { return OutgoingQueue.Count; }
}

protected BaseChannel(NetPeer peer)
{
Peer = peer;
OutgoingQueue = new Queue<NetPacket>(64);
}

public void AddToQueue(NetPacket packet)
{
lock (OutgoingQueue)
{
OutgoingQueue.Enqueue(packet);
}
AddToPeerChannelSendQueue();
}

protected void AddToPeerChannelSendQueue()
{
if (Interlocked.CompareExchange(ref _isAddedToPeerChannelSendQueue, 1, 0) == 0)
{
Peer.AddToReliableChannelSendQueue(this);
}
}

public bool SendAndCheckQueue()
{
bool hasPacketsToSend = SendNextPackets();
if (!hasPacketsToSend)
Interlocked.Exchange(ref _isAddedToPeerChannelSendQueue, 0);

return hasPacketsToSend;
}

protected abstract bool SendNextPackets();
public abstract bool ProcessPacket(NetPacket packet);
}
}
137 changes: 137 additions & 0 deletions BeatSaberPlus/CP_SDK/Network/LiteNetLib/ConnectionRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System.Net;
using System.Threading;
using CP_SDK_LiteNetLib.Utils;

namespace CP_SDK_LiteNetLib
{
internal enum ConnectionRequestResult
{
None,
Accept,
Reject,
RejectForce
}

public class ConnectionRequest
{
private readonly NetManager _listener;
private int _used;

public readonly NetDataReader Data;

internal ConnectionRequestResult Result { get; private set; }
internal long ConnectionTime;
internal byte ConnectionNumber;
public readonly IPEndPoint RemoteEndPoint;

private bool TryActivate()
{
return Interlocked.CompareExchange(ref _used, 1, 0) == 0;
}

internal void UpdateRequest(NetConnectRequestPacket connRequest)
{
if (connRequest.ConnectionTime >= ConnectionTime)
{
ConnectionTime = connRequest.ConnectionTime;
ConnectionNumber = connRequest.ConnectionNumber;
}
}

internal ConnectionRequest(
long connectionId,
byte connectionNumber,
NetDataReader netDataReader,
IPEndPoint endPoint,
NetManager listener)
{
ConnectionTime = connectionId;
ConnectionNumber = connectionNumber;
RemoteEndPoint = endPoint;
Data = netDataReader;
_listener = listener;
}

public NetPeer AcceptIfKey(string key)
{
if (!TryActivate())
return null;
try
{
if (Data.GetString() == key)
Result = ConnectionRequestResult.Accept;
}
catch
{
//NetDebug.WriteError("[AC] Invalid incoming data");
}
if (Result == ConnectionRequestResult.Accept)
return _listener.OnConnectionSolved(this, null, 0, 0);

Result = ConnectionRequestResult.Reject;
_listener.OnConnectionSolved(this, null, 0, 0);
return null;
}

/// <summary>
/// Accept connection and get new NetPeer as result
/// </summary>
/// <returns>Connected NetPeer</returns>
public NetPeer Accept()
{
if (!TryActivate())
return null;
Result = ConnectionRequestResult.Accept;
return _listener.OnConnectionSolved(this, null, 0, 0);
}

public void Reject(byte[] rejectData, int start, int length, bool force)
{
if (!TryActivate())
return;
Result = force ? ConnectionRequestResult.RejectForce : ConnectionRequestResult.Reject;
_listener.OnConnectionSolved(this, rejectData, start, length);
}

public void Reject(byte[] rejectData, int start, int length)
{
Reject(rejectData, start, length, false);
}


public void RejectForce(byte[] rejectData, int start, int length)
{
Reject(rejectData, start, length, true);
}

public void RejectForce()
{
Reject(null, 0, 0, true);
}

public void RejectForce(byte[] rejectData)
{
Reject(rejectData, 0, rejectData.Length, true);
}

public void RejectForce(NetDataWriter rejectData)
{
Reject(rejectData.Data, 0, rejectData.Length, true);
}

public void Reject()
{
Reject(null, 0, 0, false);
}

public void Reject(byte[] rejectData)
{
Reject(rejectData, 0, rejectData.Length, false);
}

public void Reject(NetDataWriter rejectData)
{
Reject(rejectData.Data, 0, rejectData.Length, false);
}
}
}
Loading

0 comments on commit 3c1fb5d

Please sign in to comment.