-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #110 from BasisVR/main
Main
- Loading branch information
Showing
172 changed files
with
10,612 additions
and
2,865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...erver/BasisNetworkClientConsole/BasisNetworkClientConsole/AvatarNetworkLoadInformation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.IO.Compression; | ||
|
||
namespace Basis.Scripts.BasisSdk.Players | ||
{ | ||
[Serializable] | ||
public struct AvatarNetworkLoadInformation | ||
{ | ||
public string AvatarBundleUrl; | ||
public string AvatarMetaUrl; | ||
public string UnlockPassword; | ||
|
||
/// <summary> | ||
/// Encodes the structure to compressed byte data using custom string serialization and DeflateStream compression. | ||
/// </summary> | ||
public byte[] EncodeToBytes() | ||
{ | ||
using var memoryStream = new MemoryStream(); | ||
using (var writer = new BinaryWriter(memoryStream)) | ||
{ | ||
WriteString(writer, AvatarBundleUrl); | ||
WriteString(writer, AvatarMetaUrl); | ||
WriteString(writer, UnlockPassword); | ||
} | ||
|
||
byte[] rawData = memoryStream.ToArray(); | ||
|
||
using var compressedStream = new MemoryStream(); | ||
using (var deflateStream = new DeflateStream(compressedStream, System.IO.Compression.CompressionLevel.Optimal, true)) | ||
{ | ||
deflateStream.Write(rawData, 0, rawData.Length); | ||
} | ||
|
||
return compressedStream.ToArray(); | ||
} | ||
|
||
/// <summary> | ||
/// Decodes from compressed byte data back to the structure using custom string deserialization and DeflateStream decompression. | ||
/// </summary> | ||
public static AvatarNetworkLoadInformation DecodeFromBytes(byte[] compressedData) | ||
{ | ||
using var compressedStream = new MemoryStream(compressedData); | ||
using var deflateStream = new DeflateStream(compressedStream, CompressionMode.Decompress); | ||
using var decompressedStream = new MemoryStream(); | ||
deflateStream.CopyTo(decompressedStream); | ||
|
||
byte[] rawData = decompressedStream.ToArray(); | ||
|
||
using var memoryStream = new MemoryStream(rawData); | ||
using var reader = new BinaryReader(memoryStream); | ||
|
||
return new AvatarNetworkLoadInformation | ||
{ | ||
AvatarBundleUrl = ReadString(reader), | ||
AvatarMetaUrl = ReadString(reader), | ||
UnlockPassword = ReadString(reader) | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Writes a string to the BinaryWriter with its length as a ushort. | ||
/// </summary> | ||
private static void WriteString(BinaryWriter writer, string value) | ||
{ | ||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(value ?? string.Empty); | ||
writer.Write((ushort)bytes.Length); // Write the length as a ushort | ||
writer.Write(bytes); // Write the string bytes | ||
} | ||
|
||
/// <summary> | ||
/// Reads a string from the BinaryReader based on its length (stored as a ushort). | ||
/// </summary> | ||
private static string ReadString(BinaryReader reader) | ||
{ | ||
ushort length = reader.ReadUInt16(); // Read the length | ||
byte[] bytes = reader.ReadBytes(length); // Read the string bytes | ||
return System.Text.Encoding.UTF8.GetString(bytes); // Convert back to a string | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
42 changes: 42 additions & 0 deletions
42
Basis Server/BasisNetworkCore/Serializable/AdditionalAvatarData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using LiteNetLib.Utils; | ||
using System; | ||
public static partial class SerializableBasis | ||
{ | ||
public struct AdditionalAvatarData | ||
{ | ||
public byte messageIndex; | ||
public byte[] array; | ||
public void Deserialize(NetDataReader Writer) | ||
{ | ||
int Bytes = Writer.AvailableBytes; | ||
if (Bytes != 0) | ||
{ | ||
messageIndex = Writer.GetByte(); | ||
|
||
byte PayloadSize = Writer.GetByte(); | ||
array = new byte[PayloadSize]; | ||
Writer.GetBytes(array, PayloadSize); | ||
//89 * 2 = 178 + 12 + 14 = 204 | ||
//now 178 for muscles, 3*4 for position 12, 4*4 for rotation 16-2 (W is half) = 204 | ||
} | ||
else | ||
{ | ||
BNL.LogError($"Unable to read Remaing bytes where {Bytes}"); | ||
} | ||
} | ||
public void Serialize(NetDataWriter Writer) | ||
{ | ||
if (array == null) | ||
{ | ||
BNL.LogError("array was null!!"); | ||
} | ||
else | ||
{ | ||
Writer.Put(messageIndex); | ||
byte Size = (byte)array.Length; | ||
Writer.Put(Size); | ||
Writer.Put(array); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.