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