2018-02-22 00:51:17 +00:00
|
|
|
|
using ChocolArm64.Memory;
|
2018-07-17 20:14:27 +01:00
|
|
|
|
using System.Text;
|
2018-02-22 00:51:17 +00:00
|
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
|
namespace Ryujinx.HLE.HOS
|
2018-02-22 00:51:17 +00:00
|
|
|
|
{
|
2018-02-26 01:44:30 +00:00
|
|
|
|
static class Homebrew
|
2018-02-22 00:51:17 +00:00
|
|
|
|
{
|
2018-07-17 20:14:27 +01:00
|
|
|
|
public const string TemporaryNroSuffix = ".ryu_tmp.nro";
|
|
|
|
|
|
2019-07-02 03:39:22 +01:00
|
|
|
|
// http://switchbrew.org/index.php?title=Homebrew_ABI
|
2018-12-06 11:16:24 +00:00
|
|
|
|
public static void WriteHbAbiData(MemoryManager memory, long position, int mainThreadHandle, string switchPath)
|
2018-02-22 00:51:17 +00:00
|
|
|
|
{
|
2019-07-02 03:39:22 +01:00
|
|
|
|
// MainThreadHandle.
|
2018-12-06 11:16:24 +00:00
|
|
|
|
WriteConfigEntry(memory, ref position, 1, 0, mainThreadHandle);
|
2018-02-26 01:44:30 +00:00
|
|
|
|
|
2019-07-02 03:39:22 +01:00
|
|
|
|
// NextLoadPath.
|
2018-12-06 11:16:24 +00:00
|
|
|
|
WriteConfigEntry(memory, ref position, 2, 0, position + 0x200, position + 0x400);
|
2018-02-26 01:44:30 +00:00
|
|
|
|
|
2019-07-02 03:39:22 +01:00
|
|
|
|
// Argv.
|
2018-12-06 11:16:24 +00:00
|
|
|
|
long argvPosition = position + 0xC00;
|
2018-08-15 19:59:51 +01:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
memory.WriteBytes(argvPosition, Encoding.ASCII.GetBytes(switchPath + "\0"));
|
2018-07-17 20:14:27 +01:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
WriteConfigEntry(memory, ref position, 5, 0, 0, argvPosition);
|
2018-08-15 19:59:51 +01:00
|
|
|
|
|
2019-07-02 03:39:22 +01:00
|
|
|
|
// AppletType.
|
2018-12-06 11:16:24 +00:00
|
|
|
|
WriteConfigEntry(memory, ref position, 7);
|
2018-02-26 01:44:30 +00:00
|
|
|
|
|
2019-07-02 03:39:22 +01:00
|
|
|
|
// EndOfList.
|
2018-12-06 11:16:24 +00:00
|
|
|
|
WriteConfigEntry(memory, ref position, 0);
|
2018-02-22 00:51:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 01:44:30 +00:00
|
|
|
|
private static void WriteConfigEntry(
|
2018-12-06 11:16:24 +00:00
|
|
|
|
MemoryManager memory,
|
|
|
|
|
ref long position,
|
|
|
|
|
int key,
|
|
|
|
|
int flags = 0,
|
|
|
|
|
long value0 = 0,
|
|
|
|
|
long value1 = 0)
|
2018-02-22 00:51:17 +00:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
memory.WriteInt32(position + 0x00, key);
|
|
|
|
|
memory.WriteInt32(position + 0x04, flags);
|
|
|
|
|
memory.WriteInt64(position + 0x08, value0);
|
|
|
|
|
memory.WriteInt64(position + 0x10, value1);
|
2018-02-22 00:51:17 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
position += 0x18;
|
2018-02-22 00:51:17 +00:00
|
|
|
|
}
|
2018-03-12 04:04:52 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
public static string ReadHbAbiNextLoadPath(MemoryManager memory, long position)
|
2018-03-12 04:04:52 +00:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
string fileName = null;
|
2018-03-12 04:04:52 +00:00
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
long key = memory.ReadInt64(position);
|
2018-03-12 04:04:52 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
if (key == 2)
|
2018-03-12 04:04:52 +00:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
long value0 = memory.ReadInt64(position + 0x08);
|
|
|
|
|
long value1 = memory.ReadInt64(position + 0x10);
|
2018-03-12 04:04:52 +00:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
fileName = MemoryHelper.ReadAsciiString(memory, value0, value1 - value0);
|
2018-03-12 04:04:52 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-12-06 11:16:24 +00:00
|
|
|
|
else if (key == 0)
|
2018-03-12 04:04:52 +00:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
position += 0x18;
|
2018-03-12 04:04:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
return fileName;
|
2018-03-12 04:04:52 +00:00
|
|
|
|
}
|
2018-02-22 00:51:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|