mirror of
https://github.com/par274/sharpemu.git
synced 2026-07-25 04:08:40 +08:00
[npManager] initial Network Platform implement (just set game title etc.)
This commit is contained in:
@@ -0,0 +1,67 @@
|
|||||||
|
// Copyright (C) 2026 SharpEmu Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
using SharpEmu.HLE;
|
||||||
|
|
||||||
|
namespace SharpEmu.Libs.Np;
|
||||||
|
|
||||||
|
public static class NpManagerExports
|
||||||
|
{
|
||||||
|
private const int NpTitleIdSize = 16;
|
||||||
|
private const int NpTitleSecretSize = 128;
|
||||||
|
|
||||||
|
[SysAbiExport(
|
||||||
|
Nid = "Ec63y59l9tw",
|
||||||
|
ExportName = "sceNpSetNpTitleId",
|
||||||
|
Target = Generation.Gen4 | Generation.Gen5,
|
||||||
|
LibraryName = "libSceNpManager")]
|
||||||
|
public static int NpSetNpTitleId(CpuContext ctx)
|
||||||
|
{
|
||||||
|
var titleIdAddress = ctx[CpuRegister.Rdi];
|
||||||
|
var titleSecretAddress = ctx[CpuRegister.Rsi];
|
||||||
|
if (titleIdAddress == 0 || titleSecretAddress == 0)
|
||||||
|
{
|
||||||
|
return SetReturn(ctx, OrbisGen2Result.ORBIS_GEN2_ERROR_INVALID_ARGUMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
Span<byte> titleId = stackalloc byte[NpTitleIdSize];
|
||||||
|
Span<byte> titleSecret = stackalloc byte[NpTitleSecretSize];
|
||||||
|
if (!ctx.Memory.TryRead(titleIdAddress, titleId) ||
|
||||||
|
!ctx.Memory.TryRead(titleSecretAddress, titleSecret))
|
||||||
|
{
|
||||||
|
return SetReturn(ctx, OrbisGen2Result.ORBIS_GEN2_ERROR_MEMORY_FAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
TraceNp($"set_np_title_id title='{ReadTitleId(titleId)}'");
|
||||||
|
return SetReturn(ctx, OrbisGen2Result.ORBIS_GEN2_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int SetReturn(CpuContext ctx, OrbisGen2Result result)
|
||||||
|
{
|
||||||
|
ctx[CpuRegister.Rax] = unchecked((ulong)(int)result);
|
||||||
|
return (int)result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ReadTitleId(ReadOnlySpan<byte> bytes)
|
||||||
|
{
|
||||||
|
var length = 0;
|
||||||
|
while (length < 12 && length < bytes.Length && bytes[length] != 0)
|
||||||
|
{
|
||||||
|
length++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return length == 0
|
||||||
|
? string.Empty
|
||||||
|
: System.Text.Encoding.ASCII.GetString(bytes[..length]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TraceNp(string message)
|
||||||
|
{
|
||||||
|
if (!string.Equals(Environment.GetEnvironmentVariable("SHARPEMU_LOG_NP"), "1", StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.Error.WriteLine($"[LOADER][TRACE] np.{message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user