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