diff options
| author | TSR Berry <20988865+TSRBerry@users.noreply.github.com> | 2023-04-08 01:22:00 +0200 |
|---|---|---|
| committer | Mary <thog@protonmail.com> | 2023-04-27 23:51:14 +0200 |
| commit | cee712105850ac3385cd0091a923438167433f9f (patch) | |
| tree | 4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs | |
| parent | cd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff) | |
Move solution and projects to src
Diffstat (limited to 'src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs')
| -rw-r--r-- | src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs b/src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs new file mode 100644 index 00000000..30b201f6 --- /dev/null +++ b/src/Ryujinx.HLE/HOS/Services/Mii/UtilityImpl.cs @@ -0,0 +1,75 @@ +using Ryujinx.Common.Utilities; +using Ryujinx.Cpu; +using Ryujinx.HLE.HOS.Services.Mii.Types; +using Ryujinx.HLE.HOS.Services.Time; +using Ryujinx.HLE.HOS.Services.Time.Clock; +using System; + +namespace Ryujinx.HLE.HOS.Services.Mii +{ + class UtilityImpl + { + private uint _x; + private uint _y; + private uint _z; + private uint _w; + + public UtilityImpl(ITickSource tickSource) + { + _x = 123456789; + _y = 362436069; + + TimeSpanType time = TimeManager.Instance.TickBasedSteadyClock.GetCurrentRawTimePoint(tickSource); + + _w = (uint)(time.NanoSeconds & uint.MaxValue); + _z = (uint)((time.NanoSeconds >> 32) & uint.MaxValue); + } + + private uint GetRandom() + { + uint t = (_x ^ (_x << 11)); + + _x = _y; + _y = _z; + _z = _w; + _w = (_w ^ (_w >> 19)) ^ (t ^ (t >> 8)); + + return _w; + } + + public int GetRandom(int end) + { + return (int)GetRandom((uint)end); + } + + public uint GetRandom(uint end) + { + uint random = GetRandom(); + + return random - random / end * end; + } + + public uint GetRandom(uint start, uint end) + { + uint random = GetRandom(); + + return random - random / (1 - start + end) * (1 - start + end) + start; + } + + public int GetRandom(int start, int end) + { + return (int)GetRandom((uint)start, (uint)end); + } + + public CreateId MakeCreateId() + { + UInt128 value = UInt128Utils.CreateRandom(); + + // Ensure the random ID generated is valid as a create id. + value &= ~new UInt128(0xC0, 0); + value |= new UInt128(0x80, 0); + + return new CreateId(value); + } + } +} |
