mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-08-02 22:17:13 +02:00
aloha
This commit is contained in:
commit
b7e1d9930d
230 changed files with 17548 additions and 0 deletions
53
Ryujinx/OsHle/Utilities/IdPool.cs
Normal file
53
Ryujinx/OsHle/Utilities/IdPool.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.OsHle.Utilities
|
||||
{
|
||||
class IdPool
|
||||
{
|
||||
private HashSet<int> Ids;
|
||||
|
||||
private int CurrId;
|
||||
private int MinId;
|
||||
private int MaxId;
|
||||
|
||||
public IdPool(int Min, int Max)
|
||||
{
|
||||
Ids = new HashSet<int>();
|
||||
|
||||
CurrId = Min;
|
||||
MinId = Min;
|
||||
MaxId = Max;
|
||||
}
|
||||
|
||||
public IdPool() : this(1, int.MaxValue) { }
|
||||
|
||||
public int GenerateId()
|
||||
{
|
||||
lock (Ids)
|
||||
{
|
||||
for (int Cnt = MinId; Cnt < MaxId; Cnt++)
|
||||
{
|
||||
if (Ids.Add(CurrId))
|
||||
{
|
||||
return CurrId;
|
||||
}
|
||||
|
||||
if (CurrId++ == MaxId)
|
||||
{
|
||||
CurrId = MinId;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public bool DeleteId(int Id)
|
||||
{
|
||||
lock (Ids)
|
||||
{
|
||||
return Ids.Remove(Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
78
Ryujinx/OsHle/Utilities/IdPoolWithObj.cs
Normal file
78
Ryujinx/OsHle/Utilities/IdPoolWithObj.cs
Normal file
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.OsHle.Utilities
|
||||
{
|
||||
class IdPoolWithObj : IEnumerable<KeyValuePair<int, object>>
|
||||
{
|
||||
private IdPool Ids;
|
||||
|
||||
private ConcurrentDictionary<int, object> Objs;
|
||||
|
||||
public IdPoolWithObj()
|
||||
{
|
||||
Ids = new IdPool();
|
||||
|
||||
Objs = new ConcurrentDictionary<int, object>();
|
||||
}
|
||||
|
||||
public int GenerateId(object Data)
|
||||
{
|
||||
int Id = Ids.GenerateId();
|
||||
|
||||
if (Id == -1 || !Objs.TryAdd(Id, Data))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
|
||||
return Id;
|
||||
}
|
||||
|
||||
public bool ReplaceData(int Id, object Data)
|
||||
{
|
||||
if (Objs.ContainsKey(Id))
|
||||
{
|
||||
Objs[Id] = Data;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public T GetData<T>(int Id)
|
||||
{
|
||||
if (Objs.TryGetValue(Id, out object Data) && Data is T)
|
||||
{
|
||||
return (T)Data;
|
||||
}
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
public void Delete(int Id)
|
||||
{
|
||||
if (Objs.TryRemove(Id, out object Obj))
|
||||
{
|
||||
if (Obj is IDisposable DisposableObj)
|
||||
{
|
||||
DisposableObj.Dispose();
|
||||
}
|
||||
|
||||
Ids.DeleteId(Id);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator<KeyValuePair<int, object>> IEnumerable<KeyValuePair<int, object>>.GetEnumerator()
|
||||
{
|
||||
return Objs.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return Objs.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
44
Ryujinx/OsHle/Utilities/MemReader.cs
Normal file
44
Ryujinx/OsHle/Utilities/MemReader.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using ChocolArm64.Memory;
|
||||
|
||||
namespace Ryujinx.OsHle.Utilities
|
||||
{
|
||||
class MemReader
|
||||
{
|
||||
private AMemory Memory;
|
||||
|
||||
public long Position { get; private set; }
|
||||
|
||||
public MemReader(AMemory Memory, long Position)
|
||||
{
|
||||
this.Memory = Memory;
|
||||
this.Position = Position;
|
||||
}
|
||||
|
||||
public byte ReadByte()
|
||||
{
|
||||
byte Value = Memory.ReadByte(Position);
|
||||
|
||||
Position++;
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
public int ReadInt32()
|
||||
{
|
||||
int Value = Memory.ReadInt32(Position);
|
||||
|
||||
Position += 4;
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
public long ReadInt64()
|
||||
{
|
||||
long Value = Memory.ReadInt64(Position);
|
||||
|
||||
Position += 8;
|
||||
|
||||
return Value;
|
||||
}
|
||||
}
|
||||
}
|
38
Ryujinx/OsHle/Utilities/MemWriter.cs
Normal file
38
Ryujinx/OsHle/Utilities/MemWriter.cs
Normal file
|
@ -0,0 +1,38 @@
|
|||
using ChocolArm64.Memory;
|
||||
|
||||
namespace Ryujinx.OsHle.Utilities
|
||||
{
|
||||
class MemWriter
|
||||
{
|
||||
private AMemory Memory;
|
||||
|
||||
public long Position { get; private set; }
|
||||
|
||||
public MemWriter(AMemory Memory, long Position)
|
||||
{
|
||||
this.Memory = Memory;
|
||||
this.Position = Position;
|
||||
}
|
||||
|
||||
public void WriteByte(byte Value)
|
||||
{
|
||||
Memory.WriteByte(Position, Value);
|
||||
|
||||
Position++;
|
||||
}
|
||||
|
||||
public void WriteInt32(int Value)
|
||||
{
|
||||
Memory.WriteInt32(Position, Value);
|
||||
|
||||
Position += 4;
|
||||
}
|
||||
|
||||
public void WriteInt64(long Value)
|
||||
{
|
||||
Memory.WriteInt64(Position, Value);
|
||||
|
||||
Position += 8;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue