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

Add Asar ContentLoader #280

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion source/Vignette/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void Dispose()

source.Stop();

while(source.TryDequeue(out var buffer))
while (source.TryDequeue(out var buffer))
{
bufferPool.Return(buffer);
}
Expand Down
26 changes: 26 additions & 0 deletions source/Vignette/Content/AsarLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Cosyne
// Licensed under GPL 3.0 with SDK Exception. See LICENSE for details.

using System;
using System.IO;
using craftersmine.Asar.Net;

namespace Vignette.Content;
internal class AsarLoader : IContentLoader<AsarArchive>
{
// while the library is capable of verifying if its a valid archive, we would like to do
// it in the content loader level too so we can catch masquerading malicious files as we
// load them.
// The first 4 bytes of an asar archive is 04 00 00 00.
private static readonly byte[] signature = new byte[] { 0x04, 0x00, 0x00, 0x00 };

public AsarArchive Load(ReadOnlySpan<byte> bytes)
{
if (!MemoryExtensions.SequenceEqual(bytes[0..4], signature))
throw new ArgumentException("Failed to find sequence \"04 00 00 00\" in byte sequence.", nameof(bytes));

// read the bytes into a stream
var stream = new MemoryStream(bytes.ToArray());
return new AsarArchive(stream);
}
}
2 changes: 1 addition & 1 deletion source/Vignette/Graphics/IProjector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IProjector
/// <summary>
/// The projector's rotation.
/// </summary>
Vector3 Rotation { get; }
Vector3 Rotation { get; }

/// <summary>
/// The projector's view matrix.
Expand Down
1 change: 1 addition & 0 deletions source/Vignette/Vignette.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ItemGroup>
<PackageReference Include="Sekai" Version="0.1.0-alpha.9" />
<PackageReference Include="StbiSharp" Version="1.2.1" />
<PackageReference Include="craftersmine.Asar.Net" Version="1.0.4" />
</ItemGroup>

</Project>
Loading