Skip to content
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
2 changes: 2 additions & 0 deletions TACTSharp/BLTE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.IO.Compression;
using System.Security.Cryptography;

using TACTSharp.Extensions;

namespace TACTSharp
{
public static class BLTE
Expand Down
4 changes: 3 additions & 1 deletion TACTSharp/CASCIndexInstance.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Win32.SafeHandles;
using System.IO.MemoryMappedFiles;

using TACTSharp.Extensions;

namespace TACTSharp
{
public sealed class CASCIndexInstance
Expand Down Expand Up @@ -82,7 +84,7 @@ unsafe public (int offset, int size, int archiveIndex) GetIndexInfo(Span<byte> e

var indexHigh = entrySpan[header.entryKeyBytes];
var indexLow = entrySpan.Slice(header.entryKeyBytes + 1, 4).ReadInt32BE();
var indexSize = System.Buffers.Binary.BinaryPrimitives.ReadInt32LittleEndian(entrySpan.Slice(header.entryKeyBytes + 5, header.entrySizeBytes)) - 30;
var indexSize = entrySpan.Slice(header.entryKeyBytes + 5, header.entrySizeBytes).ReadInt32LE() - 30;

var archiveIndex = (indexHigh << 2 | (byte)((indexLow & 0xC0000000) >> 30));
var archiveOffset = (indexLow & 0x3FFFFFFF) + 30;
Expand Down
2 changes: 2 additions & 0 deletions TACTSharp/Extensions/BinarySearchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using TACTSharp.Utils;

namespace TACTSharp.Extensions
{
internal static class BinarySearchExtensions
Expand Down
38 changes: 37 additions & 1 deletion TACTSharp/Extensions/SpanExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System.Runtime.CompilerServices;
using System.Buffers.Binary;
using System.Runtime.CompilerServices;
using System.Text;

using TACTSharp.Utils;

namespace TACTSharp.Extensions
{
Expand All @@ -11,5 +15,37 @@ public static StridedReadOnlySpan<T> WithStride<T>(this ReadOnlySpan<T> span, in
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static StridedSpan<T> WithStride<T>(this Span<T> span, int stride)
=> new(span, stride);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ushort ReadUInt16BE(this ReadOnlySpan<byte> source)
=> BinaryPrimitives.ReadUInt16BigEndian(source);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static short ReadInt16BE(this ReadOnlySpan<byte> source)
=> BinaryPrimitives.ReadInt16BigEndian(source);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ReadInt24BE(this ReadOnlySpan<byte> source)
=> source[2] | source[1] << 8 | source[0] << 16;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ReadInt32BE(this ReadOnlySpan<byte> source)
=> BinaryPrimitives.ReadInt32BigEndian(source);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int ReadInt32LE(this ReadOnlySpan<byte> source)
=> BinaryPrimitives.ReadInt32LittleEndian(source);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint ReadUInt32BE(this ReadOnlySpan<byte> source)
=> BinaryPrimitives.ReadUInt32BigEndian(source);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long ReadInt40BE(this ReadOnlySpan<byte> source)
=> source[4] | source[3] << 8 | source[2] << 16 | source[1] << 24 | source[0] << 32;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string ReadNullTermString(this ReadOnlySpan<byte> source)
=> Encoding.UTF8.GetString(source[..source.IndexOf((byte)0)]);
}
}
2 changes: 2 additions & 0 deletions TACTSharp/IndexInstance.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Win32.SafeHandles;
using System.IO.MemoryMappedFiles;

using TACTSharp.Extensions;

namespace TACTSharp
{
// mostly based on schlumpf's implementation, but with some changes because i dont know how to port some c++ things to c# properly
Expand Down
2 changes: 2 additions & 0 deletions TACTSharp/InstallInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections;
using System.IO.MemoryMappedFiles;

using TACTSharp.Extensions;

namespace TACTSharp
{
public class InstallInstance
Expand Down
2 changes: 2 additions & 0 deletions TACTSharp/TVFSInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;

using TACTSharp.Extensions;
using TACTSharp.Interfaces;
using static TACTSharp.RootInstance;

Expand Down
40 changes: 0 additions & 40 deletions TACTSharp/Utils/Extensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Runtime.CompilerServices;

namespace TACTSharp
namespace TACTSharp.Utils
{
internal readonly ref struct StridedSpan<T>(Span<T> data, int stride)
{
Expand Down
Loading