This repository has been archived by the owner on Oct 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxbox.c
94 lines (76 loc) · 1.95 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
#include <memory.h>
#include <sys/stat.h>
#include <hal/xbox.h>
#include <hal/fileio.h>
#include <xboxkrnl/xboxkrnl.h>
#include <stdio.h>
#include <openxdk/debug.h>
#define KernelMode 0
void XReboot()
{
HalReturnToFirmware(ReturnFirmwareReboot);
}
int XGetTickCount()
{
return KeTickCount;
}
void XSleep(int milliseconds)
{
LARGE_INTEGER interval;
interval.QuadPart = (long long) milliseconds * -10000;
KeDelayExecutionThread(KernelMode, FALSE, &interval);
}
/**
* Launches an XBE. Examples of xbePath might be:
* c:\\blah.xbe
* c:/foo/bar.xbe
* If the XBE is able to be launched, this method will
* not return. If there is a problem, then it return.
*/
void XLaunchXBE(char *xbePath)
{
struct stat statbuf;
if (stat(xbePath, &statbuf) < 0)
return;
if (LaunchDataPage == NULL)
LaunchDataPage = MmAllocateContiguousMemory(0x1000);
if (LaunchDataPage == NULL)
return;
MmPersistContiguousMemory(LaunchDataPage, 0x1000, TRUE);
memset((void*)LaunchDataPage, 0, 0x1000);
LaunchDataPage->Header.dwLaunchDataType = 0xFFFFFFFF;
LaunchDataPage->Header.dwTitleId = 0;
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 != NULL)
{
*lastSlash = ';';
HalReturnToFirmware(ReturnFirmwareQuickReboot);
}
// if we couldn't find a trailing slash, the conversion to
// the xbox path mustn't have worked, so we will return
}
int XCreateThread(XThreadCallback callback, void *args1, void *args2)
{
ULONG id;
HANDLE handle;
NTSTATUS status = PsCreateSystemThreadEx(
(HANDLE)&handle,
0,
65536,
0,
&id,
args1,
args2,
FALSE,
FALSE,
(PKSTART_ROUTINE)callback);
if (handle == 0) {
return -1;
}
return (unsigned int)handle;
}