mirror of
https://github.com/Ryubing/Ryujinx.git
synced 2025-12-01 02:02:47 -05:00
Move solution and projects to src
This commit is contained in:
8
src/Ryujinx.HLE/HOS/Services/Nfc/IAmManager.cs
Normal file
8
src/Ryujinx.HLE/HOS/Services/Nfc/IAmManager.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc
|
||||
{
|
||||
[Service("nfc:am")]
|
||||
class IAmManager : IpcService
|
||||
{
|
||||
public IAmManager(ServiceCtx context) { }
|
||||
}
|
||||
}
|
||||
19
src/Ryujinx.HLE/HOS/Services/Nfc/ISystemManager.cs
Normal file
19
src/Ryujinx.HLE/HOS/Services/Nfc/ISystemManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.NfcManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc
|
||||
{
|
||||
[Service("nfc:sys")]
|
||||
class ISystemManager : IpcService
|
||||
{
|
||||
public ISystemManager(ServiceCtx context) { }
|
||||
|
||||
[CommandCmif(0)]
|
||||
// CreateSystemInterface() -> object<nn::nfc::detail::ISystem>
|
||||
public ResultCode CreateSystemInterface(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new INfc(NfcPermissionLevel.System));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/Ryujinx.HLE/HOS/Services/Nfc/IUserManager.cs
Normal file
19
src/Ryujinx.HLE/HOS/Services/Nfc/IUserManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.NfcManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc
|
||||
{
|
||||
[Service("nfc:user")]
|
||||
class IUserManager : IpcService
|
||||
{
|
||||
public IUserManager(ServiceCtx context) { }
|
||||
|
||||
[CommandCmif(0)]
|
||||
// CreateUserInterface() -> object<nn::nfc::detail::IUser>
|
||||
public ResultCode CreateUserInterface(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new INfc(NfcPermissionLevel.User));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Ryujinx.HLE/HOS/Services/Nfc/Mifare/IUserManager.cs
Normal file
8
src/Ryujinx.HLE/HOS/Services/Nfc/Mifare/IUserManager.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Mifare
|
||||
{
|
||||
[Service("nfc:mf:u")]
|
||||
class IUserManager : IpcService
|
||||
{
|
||||
public IUserManager(ServiceCtx context) { }
|
||||
}
|
||||
}
|
||||
63
src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/INfc.cs
Normal file
63
src/Ryujinx.HLE/HOS/Services/Nfc/NfcManager/INfc.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager
|
||||
{
|
||||
class INfc : IpcService
|
||||
{
|
||||
private NfcPermissionLevel _permissionLevel;
|
||||
private State _state;
|
||||
|
||||
public INfc(NfcPermissionLevel permissionLevel)
|
||||
{
|
||||
_permissionLevel = permissionLevel;
|
||||
_state = State.NonInitialized;
|
||||
}
|
||||
|
||||
[CommandCmif(0)]
|
||||
[CommandCmif(400)] // 4.0.0+
|
||||
// Initialize(u64, u64, pid, buffer<unknown, 5>)
|
||||
public ResultCode Initialize(ServiceCtx context)
|
||||
{
|
||||
_state = State.Initialized;
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceNfc, new { _permissionLevel });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(1)]
|
||||
[CommandCmif(401)] // 4.0.0+
|
||||
// Finalize()
|
||||
public ResultCode Finalize(ServiceCtx context)
|
||||
{
|
||||
_state = State.NonInitialized;
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceNfc, new { _permissionLevel });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(2)]
|
||||
[CommandCmif(402)] // 4.0.0+
|
||||
// GetState() -> u32
|
||||
public ResultCode GetState(ServiceCtx context)
|
||||
{
|
||||
context.ResponseData.Write((int)_state);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
[CommandCmif(3)]
|
||||
[CommandCmif(403)] // 4.0.0+
|
||||
// IsNfcEnabled() -> b8
|
||||
public ResultCode IsNfcEnabled(ServiceCtx context)
|
||||
{
|
||||
// NOTE: Write false value here could make nfp service not called.
|
||||
context.ResponseData.Write(true);
|
||||
|
||||
Logger.Stub?.PrintStub(LogClass.ServiceNfc, new { _permissionLevel });
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager
|
||||
{
|
||||
enum NfcPermissionLevel
|
||||
{
|
||||
User,
|
||||
System
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.NfcManager
|
||||
{
|
||||
enum State
|
||||
{
|
||||
NonInitialized,
|
||||
Initialized
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
[JsonSerializable(typeof(VirtualAmiiboFile))]
|
||||
internal partial class AmiiboJsonSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
}
|
||||
19
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IDebugManager.cs
Normal file
19
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IDebugManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
[Service("nfp:dbg")]
|
||||
class IAmManager : IpcService
|
||||
{
|
||||
public IAmManager(ServiceCtx context) { }
|
||||
|
||||
[CommandCmif(0)]
|
||||
// CreateDebugInterface() -> object<nn::nfp::detail::IDebug>
|
||||
public ResultCode CreateDebugInterface(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new INfp(NfpPermissionLevel.Debug));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ISystemManager.cs
Normal file
19
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ISystemManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
[Service("nfp:sys")]
|
||||
class ISystemManager : IpcService
|
||||
{
|
||||
public ISystemManager(ServiceCtx context) { }
|
||||
|
||||
[CommandCmif(0)]
|
||||
// CreateSystemInterface() -> object<nn::nfp::detail::ISystem>
|
||||
public ResultCode CreateSystemInterface(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new INfp(NfpPermissionLevel.System));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IUserManager.cs
Normal file
19
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/IUserManager.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
[Service("nfp:user")]
|
||||
class IUserManager : IpcService
|
||||
{
|
||||
public IUserManager(ServiceCtx context) { }
|
||||
|
||||
[CommandCmif(0)]
|
||||
// CreateUserInterface() -> object<nn::nfp::detail::IUser>
|
||||
public ResultCode CreateUserInterface(ServiceCtx context)
|
||||
{
|
||||
MakeObject(context, new INfp(NfpPermissionLevel.User));
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
1000
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs
Normal file
1000
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/NfpManager/INfp.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
static class AmiiboConstants
|
||||
{
|
||||
public const int UuidMaxLength = 10;
|
||||
public const int ApplicationAreaSize = 0xD8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x40)]
|
||||
struct CommonInfo
|
||||
{
|
||||
public ushort LastWriteYear;
|
||||
public byte LastWriteMonth;
|
||||
public byte LastWriteDay;
|
||||
public ushort WriteCounter;
|
||||
public ushort Version;
|
||||
public uint ApplicationAreaSize;
|
||||
public Array52<byte> Reserved;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
enum DeviceType : uint
|
||||
{
|
||||
Amiibo
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x40)]
|
||||
struct ModelInfo
|
||||
{
|
||||
public ushort CharacterId;
|
||||
public byte CharacterVariant;
|
||||
public byte Series;
|
||||
public ushort ModelNumber;
|
||||
public byte Type;
|
||||
public Array57<byte> Reserved;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
enum MountTarget : uint
|
||||
{
|
||||
Rom = 1,
|
||||
Ram = 2,
|
||||
All = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Hid;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
class NfpDevice
|
||||
{
|
||||
public KEvent ActivateEvent;
|
||||
public KEvent DeactivateEvent;
|
||||
|
||||
public void SignalActivate() => ActivateEvent.ReadableEvent.Signal();
|
||||
public void SignalDeactivate() => DeactivateEvent.ReadableEvent.Signal();
|
||||
|
||||
public NfpDeviceState State = NfpDeviceState.Unavailable;
|
||||
|
||||
public PlayerIndex Handle;
|
||||
public NpadIdType NpadIdType;
|
||||
|
||||
public string AmiiboId;
|
||||
|
||||
public bool UseRandomUuid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
enum NfpDeviceState
|
||||
{
|
||||
Initialized = 0,
|
||||
SearchingForTag = 1,
|
||||
TagFound = 2,
|
||||
TagRemoved = 3,
|
||||
TagMounted = 4,
|
||||
Unavailable = 5,
|
||||
Finalized = 6
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
enum NfpPermissionLevel
|
||||
{
|
||||
Debug,
|
||||
User,
|
||||
System
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.HLE.HOS.Services.Mii.Types;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x100)]
|
||||
struct RegisterInfo
|
||||
{
|
||||
public CharInfo MiiCharInfo;
|
||||
public ushort FirstWriteYear;
|
||||
public byte FirstWriteMonth;
|
||||
public byte FirstWriteDay;
|
||||
public Array41<byte> Nickname;
|
||||
public byte FontRegion;
|
||||
public Array64<byte> Reserved1;
|
||||
public Array58<byte> Reserved2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
enum State
|
||||
{
|
||||
NonInitialized = 0,
|
||||
Initialized = 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Ryujinx.Common.Memory;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential, Size = 0x58)]
|
||||
struct TagInfo
|
||||
{
|
||||
public Array10<byte> Uuid;
|
||||
public byte UuidLength;
|
||||
public Array21<byte> Reserved1;
|
||||
public uint Protocol;
|
||||
public uint TagType;
|
||||
public Array6<byte> Reserved2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager
|
||||
{
|
||||
struct VirtualAmiiboFile
|
||||
{
|
||||
public uint FileVersion { get; set; }
|
||||
public byte[] TagUuid { get; set; }
|
||||
public string AmiiboId { get; set; }
|
||||
public DateTime FirstWriteDate { get; set; }
|
||||
public DateTime LastWriteDate { get; set; }
|
||||
public ushort WriteCounter { get; set; }
|
||||
public List<VirtualAmiiboApplicationArea> ApplicationAreas { get; set; }
|
||||
}
|
||||
|
||||
struct VirtualAmiiboApplicationArea
|
||||
{
|
||||
public uint ApplicationAreaId { get; set; }
|
||||
public byte[] ApplicationArea { get; set; }
|
||||
}
|
||||
}
|
||||
18
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ResultCode.cs
Normal file
18
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/ResultCode.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
public enum ResultCode
|
||||
{
|
||||
ModuleId = 115,
|
||||
ErrorCodeShift = 9,
|
||||
|
||||
Success = 0,
|
||||
|
||||
DeviceNotFound = (64 << ErrorCodeShift) | ModuleId,
|
||||
WrongArgument = (65 << ErrorCodeShift) | ModuleId,
|
||||
WrongDeviceState = (73 << ErrorCodeShift) | ModuleId,
|
||||
NfcDisabled = (80 << ErrorCodeShift) | ModuleId,
|
||||
TagNotFound = (97 << ErrorCodeShift) | ModuleId,
|
||||
ApplicationAreaIsNull = (128 << ErrorCodeShift) | ModuleId,
|
||||
ApplicationAreaAlreadyCreated = (168 << ErrorCodeShift) | ModuleId
|
||||
}
|
||||
}
|
||||
204
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs
Normal file
204
src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using Ryujinx.Common.Configuration;
|
||||
using Ryujinx.Common.Memory;
|
||||
using Ryujinx.Common.Utilities;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Services.Mii;
|
||||
using Ryujinx.HLE.HOS.Services.Mii.Types;
|
||||
using Ryujinx.HLE.HOS.Services.Nfc.Nfp.NfpManager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
|
||||
{
|
||||
static class VirtualAmiibo
|
||||
{
|
||||
private static uint _openedApplicationAreaId;
|
||||
|
||||
private static readonly AmiiboJsonSerializerContext SerializerContext = AmiiboJsonSerializerContext.Default;
|
||||
|
||||
public static byte[] GenerateUuid(string amiiboId, bool useRandomUuid)
|
||||
{
|
||||
if (useRandomUuid)
|
||||
{
|
||||
return GenerateRandomUuid();
|
||||
}
|
||||
|
||||
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
if (virtualAmiiboFile.TagUuid.Length == 0)
|
||||
{
|
||||
virtualAmiiboFile.TagUuid = GenerateRandomUuid();
|
||||
|
||||
SaveAmiiboFile(virtualAmiiboFile);
|
||||
}
|
||||
|
||||
return virtualAmiiboFile.TagUuid;
|
||||
}
|
||||
|
||||
private static byte[] GenerateRandomUuid()
|
||||
{
|
||||
byte[] uuid = new byte[9];
|
||||
|
||||
Random.Shared.NextBytes(uuid);
|
||||
|
||||
uuid[3] = (byte)(0x88 ^ uuid[0] ^ uuid[1] ^ uuid[2]);
|
||||
uuid[8] = (byte)(uuid[3] ^ uuid[4] ^ uuid[5] ^ uuid[6]);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public static CommonInfo GetCommonInfo(string amiiboId)
|
||||
{
|
||||
VirtualAmiiboFile amiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
return new CommonInfo()
|
||||
{
|
||||
LastWriteYear = (ushort)amiiboFile.LastWriteDate.Year,
|
||||
LastWriteMonth = (byte)amiiboFile.LastWriteDate.Month,
|
||||
LastWriteDay = (byte)amiiboFile.LastWriteDate.Day,
|
||||
WriteCounter = amiiboFile.WriteCounter,
|
||||
Version = 1,
|
||||
ApplicationAreaSize = AmiiboConstants.ApplicationAreaSize,
|
||||
Reserved = new Array52<byte>()
|
||||
};
|
||||
}
|
||||
|
||||
public static RegisterInfo GetRegisterInfo(ITickSource tickSource, string amiiboId, string nickname)
|
||||
{
|
||||
VirtualAmiiboFile amiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
UtilityImpl utilityImpl = new UtilityImpl(tickSource);
|
||||
CharInfo charInfo = new CharInfo();
|
||||
|
||||
charInfo.SetFromStoreData(StoreData.BuildDefault(utilityImpl, 0));
|
||||
|
||||
charInfo.Nickname = Nickname.FromString(nickname);
|
||||
|
||||
RegisterInfo registerInfo = new RegisterInfo()
|
||||
{
|
||||
MiiCharInfo = charInfo,
|
||||
FirstWriteYear = (ushort)amiiboFile.FirstWriteDate.Year,
|
||||
FirstWriteMonth = (byte)amiiboFile.FirstWriteDate.Month,
|
||||
FirstWriteDay = (byte)amiiboFile.FirstWriteDate.Day,
|
||||
FontRegion = 0,
|
||||
Reserved1 = new Array64<byte>(),
|
||||
Reserved2 = new Array58<byte>()
|
||||
};
|
||||
"Ryujinx"u8.CopyTo(registerInfo.Nickname.AsSpan());
|
||||
|
||||
return registerInfo;
|
||||
}
|
||||
|
||||
public static bool OpenApplicationArea(string amiiboId, uint applicationAreaId)
|
||||
{
|
||||
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
if (virtualAmiiboFile.ApplicationAreas.Any(item => item.ApplicationAreaId == applicationAreaId))
|
||||
{
|
||||
_openedApplicationAreaId = applicationAreaId;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static byte[] GetApplicationArea(string amiiboId)
|
||||
{
|
||||
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
foreach (VirtualAmiiboApplicationArea applicationArea in virtualAmiiboFile.ApplicationAreas)
|
||||
{
|
||||
if (applicationArea.ApplicationAreaId == _openedApplicationAreaId)
|
||||
{
|
||||
return applicationArea.ApplicationArea;
|
||||
}
|
||||
}
|
||||
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
public static bool CreateApplicationArea(string amiiboId, uint applicationAreaId, byte[] applicationAreaData)
|
||||
{
|
||||
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
if (virtualAmiiboFile.ApplicationAreas.Any(item => item.ApplicationAreaId == applicationAreaId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtualAmiiboFile.ApplicationAreas.Add(new VirtualAmiiboApplicationArea()
|
||||
{
|
||||
ApplicationAreaId = applicationAreaId,
|
||||
ApplicationArea = applicationAreaData
|
||||
});
|
||||
|
||||
SaveAmiiboFile(virtualAmiiboFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SetApplicationArea(string amiiboId, byte[] applicationAreaData)
|
||||
{
|
||||
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
|
||||
|
||||
if (virtualAmiiboFile.ApplicationAreas.Any(item => item.ApplicationAreaId == _openedApplicationAreaId))
|
||||
{
|
||||
for (int i = 0; i < virtualAmiiboFile.ApplicationAreas.Count; i++)
|
||||
{
|
||||
if (virtualAmiiboFile.ApplicationAreas[i].ApplicationAreaId == _openedApplicationAreaId)
|
||||
{
|
||||
virtualAmiiboFile.ApplicationAreas[i] = new VirtualAmiiboApplicationArea()
|
||||
{
|
||||
ApplicationAreaId = _openedApplicationAreaId,
|
||||
ApplicationArea = applicationAreaData
|
||||
};
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SaveAmiiboFile(virtualAmiiboFile);
|
||||
}
|
||||
}
|
||||
|
||||
private static VirtualAmiiboFile LoadAmiiboFile(string amiiboId)
|
||||
{
|
||||
Directory.CreateDirectory(Path.Join(AppDataManager.BaseDirPath, "system", "amiibo"));
|
||||
|
||||
string filePath = Path.Join(AppDataManager.BaseDirPath, "system", "amiibo", $"{amiiboId}.json");
|
||||
|
||||
VirtualAmiiboFile virtualAmiiboFile;
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
virtualAmiiboFile = JsonHelper.DeserializeFromFile(filePath, SerializerContext.VirtualAmiiboFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
virtualAmiiboFile = new VirtualAmiiboFile()
|
||||
{
|
||||
FileVersion = 0,
|
||||
TagUuid = Array.Empty<byte>(),
|
||||
AmiiboId = amiiboId,
|
||||
FirstWriteDate = DateTime.Now,
|
||||
LastWriteDate = DateTime.Now,
|
||||
WriteCounter = 0,
|
||||
ApplicationAreas = new List<VirtualAmiiboApplicationArea>()
|
||||
};
|
||||
|
||||
SaveAmiiboFile(virtualAmiiboFile);
|
||||
}
|
||||
|
||||
return virtualAmiiboFile;
|
||||
}
|
||||
|
||||
private static void SaveAmiiboFile(VirtualAmiiboFile virtualAmiiboFile)
|
||||
{
|
||||
string filePath = Path.Join(AppDataManager.BaseDirPath, "system", "amiibo", $"{virtualAmiiboFile.AmiiboId}.json");
|
||||
JsonHelper.SerializeToFile(filePath, virtualAmiiboFile, SerializerContext.VirtualAmiiboFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user