daily update on 20240828 by nitload youmu, autotexture added

This commit is contained in:
Nitload
2024-08-28 10:58:31 +08:00
parent d082071f2d
commit 1ee4e4a42f
586 changed files with 60910 additions and 123106 deletions
+60 -29
View File
@@ -1,4 +1,34 @@
using StgSharp.Data;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="RandomGenerator.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.Data;
using System;
using System.IO;
@@ -14,15 +44,16 @@ namespace StgSharp.Data
public class RandomGenerator
{
private byte[] currentKey;
private readonly byte[] originKey;
private byte[] currentKey;
private int cycleCount;
private SHA512 hash;
public RandomGenerator():this(DateTime.UtcNow.ToBinary())
public RandomGenerator() : this(DateTime.UtcNow.ToBinary())
{
}
public RandomGenerator(object source)
@@ -77,28 +108,38 @@ namespace StgSharp.Data
return source.Read<int>(cycleCount % 4);
}
public byte GenRandomInt8()
{
cycleCount++;
if (cycleCount % 64 == 0)
{
PrivateRand();
}
return currentKey[cycleCount % 64];
}
public float GenRandomSingle()
{
cycleCount++;
while (true)
{
M128 source = PrivateRand();
uint
temp0 = source.Read<uint>(0),
temp1 = source.Read<uint>(2);
if (temp0 * temp1 != 0)
{
float ret = (temp0 % temp1) * 1.0f / temp1;
float ret = ((temp0 % temp1) * 1.0f) / temp1;
if (ret < 0.335f)
{
ret = ret * (ret * -0.7811934f + 1.4489113f);
ret = ret * ((ret * (-0.7811934f)) + 1.4489113f);
}
else
else
{
ret = ret * (ret * -0.1158368f + 1.0580600f) + 0.0590584f;
ret = (ret * ((ret * (-0.1158368f)) + 1.0580600f)) + 0.0590584f;
}
if (ret > 1)
{
@@ -111,14 +152,11 @@ namespace StgSharp.Data
}
public byte GenRandomInt8()
public void Reset()
{
cycleCount++;
if (cycleCount % 64 == 0)
{
PrivateRand();
}
return (byte)(currentKey[ cycleCount % 64 ]);
currentKey = originKey;
cycleCount = 0;
}
private unsafe M128 PrivateRand()
@@ -127,16 +165,16 @@ namespace StgSharp.Data
M128 ret;
fixed (byte* bptr = currentKey)
{
switch ((cycleCount % 16) / 4)
switch ((cycleCount % 16) / 4)
{
case 0:
ret= *((M128*)bptr + 0);break;
ret = *(((M128*)bptr) + 0); break;
case 1:
ret= *((M128*)bptr + 1);break;
ret = *(((M128*)bptr) + 1); break;
case 2:
ret= *((M128*)bptr + 2);break;
ret = *(((M128*)bptr) + 2); break;
case 3:
ret= *((M128*)bptr + 3);break;
ret = *(((M128*)bptr) + 3); break;
default:
throw new InvalidOperationException();
}
@@ -145,12 +183,5 @@ namespace StgSharp.Data
return ret;
}
public void Reset()
{
currentKey = originKey;
cycleCount = 0;
}
}
}