-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathxbox.c
93 lines (74 loc) · 2.62 KB
/
xbox.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2004 Craig Edwards
// SPDX-FileCopyrightText: 2006 Richard Osborne
// SPDX-FileCopyrightText: 2017-2020 Stefan Schmidt
// SPDX-FileCopyrightText: 2022 Erik Abair
#include <string.h>
// #include <xboxrt/stat.h>
#include <hal/xbox.h>
#include <hal/fileio.h>
#include <xboxkrnl/xboxkrnl.h>
#include <stdio.h>
#include <hal/debug.h>
#define KernelMode 0
#define LaunchDataPageSize 0x1000
void XReboot()
{
HalReturnToFirmware(HalRebootRoutine);
}
int XGetLaunchInfo(unsigned long *launchDataType, const unsigned char **launchData)
{
*launchDataType = LDT_NONE;
*launchData = NULL;
if (LaunchDataPage == NULL) {
LaunchDataPage = MmAllocateContiguousMemory(LaunchDataPageSize);
if (LaunchDataPage == NULL) {
return -1;
}
memset(LaunchDataPage, 0, LaunchDataPageSize);
LaunchDataPage->Header.dwLaunchDataType = LDT_FROM_DASHBOARD;
}
*launchDataType = LaunchDataPage->Header.dwLaunchDataType;
*launchData = LaunchDataPage->LaunchData;
return 0;
}
void XLaunchXBE(const char *xbePath)
{
XLaunchXBEEx(xbePath, NULL);
}
void XLaunchXBEEx(const char *xbePath, const void *launchData)
{
if (LaunchDataPage == NULL) {
LaunchDataPage = MmAllocateContiguousMemory(LaunchDataPageSize);
if (LaunchDataPage == NULL) {
return;
}
}
// For ease of debugging.
PLAUNCH_DATA_PAGE launchDataPage = LaunchDataPage;
MmPersistContiguousMemory(launchDataPage, LaunchDataPageSize, TRUE);
memset((void*)launchDataPage, 0, LaunchDataPageSize);
launchDataPage->Header.dwLaunchDataType = LDT_TITLE;
launchDataPage->Header.dwTitleId = CURRENT_XBE_HEADER->CertificateHeader->TitleID;
launchDataPage->Header.dwFlags = 0x0000;
if (!xbePath) {
launchDataPage->Header.dwLaunchDataType = LDT_LAUNCH_DASHBOARD;
} else {
XConvertDOSFilenameToXBOX(xbePath, launchDataPage->Header.szLaunchPath);
// one last thing... xbePath now looks like:
// \Device\Harddisk0\Partition2\blah\doom.xbe
// but it has to look like:
// \Device\Harddisk0\Partition2\blah;doom.xbe
char *lastSlash = strrchr(launchDataPage->Header.szLaunchPath, '\\');
if (!lastSlash) {
// if we couldn't find a trailing slash, the conversion to
// the xbox path mustn't have worked, so we will return
return;
}
*lastSlash = ';';
}
if (launchData) {
memcpy(launchDataPage->LaunchData, launchData, sizeof(launchDataPage->LaunchData));
}
HalReturnToFirmware(HalQuickRebootRoutine);
}