daily update on 20240508 by nitload youmu, partical added

This commit is contained in:
YoumuLiu
2024-05-09 04:14:36 +08:00
parent fc19ab3298
commit 56459deec5
58 changed files with 1507 additions and 431 deletions
+72 -13
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="DataSegment.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Collections.Generic;
@@ -10,31 +40,43 @@ using System.Threading.Tasks;
namespace StgSharp.Data
{
[StructLayout(LayoutKind.Explicit)]
public unsafe struct SSDSegment
[StructLayout(LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16)]
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
{
[FieldOffset(16)] public fixed byte Data[16 * 16];
[FieldOffset(16)] public fixed byte Data[16 * (StgSharp.ssdSegmentLength - 1)];
[FieldOffset(12)] public int DataHash;
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
[FieldOffset(8)] public int PreviousHash;
[FieldOffset(0 * 16)] public SSDSegmentHead Head;
public SSDSegment(int previousHash)
{
this.PreviousHash = previousHash;
}
public int ID
public static SSDSegment FromStream(byte[] stream)
{
get { return Head.globalID; }
set { Head.globalID = value; }
if (stream.Length != 16 * StgSharp.ssdSegmentLength)
{
throw new ArgumentException();
}
SSDSegment ret = new SSDSegment();
fixed (byte* bptr = stream)
{
ret.Head.data = *(M128*)bptr;
for (int i = 1; i < StgSharp.ssdSegmentLength; i++)
{
ret.WriteData<M128>(i - 1, *(M128*)(bptr + 16 * i));
}
}
return ret;
}
public byte this[int index]
{
get
{
if (index > (16 * 14) - 1)
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
{
throw new IndexOutOfRangeException();
}
@@ -43,7 +85,7 @@ namespace StgSharp.Data
set
{
if (index > (16 * 14) - 1)
if (index > (16 * (StgSharp.ssdSegmentLength - 1)) - 1)
{
throw new IndexOutOfRangeException();
}
@@ -51,6 +93,12 @@ namespace StgSharp.Data
}
}
public int ID
{
get { return Head.globalID; }
set { Head.globalID = value; }
}
public short Size => Head.size;
public void FillRandomBytes(int begin)
@@ -67,7 +115,7 @@ namespace StgSharp.Data
public byte[] GetBytes()
{
byte[] ret = new byte[16 * 18];
byte[] ret = new byte[16 * StgSharp.ssdSegmentLength];
fixed (M128* mptr = &Head.data)
{
fixed (byte* aptr = ret)
@@ -90,7 +138,7 @@ namespace StgSharp.Data
fixed (M128* mptr = &Head.data)
{
Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < 16; i += 1)
for (int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1)
{
v += (*vptr) * 31;
}
@@ -106,7 +154,7 @@ namespace StgSharp.Data
fixed (M128* mptr = &Head.data)
{
Vector4* vptr = (Vector4*)mptr;
for (int i = 0; i < 18; i++)
for (int i = 0; i < StgSharp.ssdSegmentLength; i++)
{
ret = (ret + (*vptr).GetHashCode()) * 31;
}
@@ -122,6 +170,7 @@ namespace StgSharp.Data
return *(tptr + index);
}
}
public unsafe void WriteData<T>(int index, T value) where T : struct
{
fixed (byte* bptr = Data)
@@ -131,6 +180,16 @@ namespace StgSharp.Data
}
}
int IComparable<int>.CompareTo(int other)
{
return ID.CompareTo(other);
}
int IComparable<SSDSegment>.CompareTo(SSDSegment other)
{
return ID.CompareTo(other.ID);
}
}
}