Última actividad 1 month ago

rifts-init.c Sin formato
1#include <stdio.h>
2#include <hidapi/hidapi.h>
3#include <stdint.h>
4#include <string.h>
5
6// Build:
7// gcc rifts-init.c -lhidapi-libusb -o rifts-init
8
9void printBuffer(char *buff, int length) {
10 for (int i = 0; i < length; i++) {
11 printf("%02x ", buff[i] & 0xFF);
12 }
13
14 printf("\n");
15}
16
17void clear_buff(char *buff, int length) {
18 for (int i = 0; i < length; i++) {
19 buff[i] = 0x00;
20 }
21}
22
23int get_report(hid_device *hid, char id, char *buff, int length) {
24 buff[0] = id;
25 clear_buff(&buff[1], length-1);
26 return hid_get_feature_report(hid, buff, length);
27}
28
29typedef struct DeviceInfo {
30 char cmd;
31 uint16_t v_resolution;
32 uint16_t h_resolution;
33 uint16_t unk0;
34 char refreshRate;
35 int32_t unk1;
36 int32_t unk2;
37 int32_t unk3;
38 uint16_t unk4;
39} __attribute__((aligned(1), packed));
40
41int main() {
42 struct hid_device_info* dev = hid_enumerate(0x2833, 0x0051);
43 struct DeviceInfo devInfo;
44
45 if (dev == NULL) {
46 printf("Not found\n");
47 return 1;
48 }
49 struct hid_device_info *d = dev;
50 while (d != NULL) {
51 //printf("%d\n", d->interface_number);
52 if (d->interface_number == 0x07) {
53 printf("FOUND\n");
54 break;
55 }
56 d = d->next;
57 }
58
59 if (d == NULL) {
60 printf("Not found\n");
61 return 1;
62 }
63
64 hid_device *hid = hid_open_path(d->path);
65 if (hid == NULL) {
66 printf("FAIL %s\n", hid_error(hid));
67 return 1;
68 }
69
70 char buff[65];
71
72 int b = get_report(hid, 0x06, buff, 22);
73 memcpy(&devInfo, buff, 22);
74 printBuffer(buff, b);
75
76 clear_buff(buff, 65);
77 printf("%d\n", sizeof(devInfo));
78 printf("Horiz: %u\nVert: %u\nHz: %u\n", devInfo.h_resolution, devInfo.v_resolution, devInfo.refreshRate);
79 printf("Unk0: %u\nUnk1: %d\nUnk2: %d\nUnk3: %d\nUnk4: %u\n", devInfo.unk0, devInfo.unk1, devInfo.unk2, devInfo.unk3, devInfo.unk4);
80
81 clear_buff(buff, 65);
82 buff[0] = 0x14;
83 buff[1] = 0x01;
84
85 hid_send_feature_report(hid, buff, 2); // Enables Camera Device
86
87 clear_buff(buff, 65);
88 printf("Sending 0x0A 0x02\n");
89
90 buff[0] = 0x0A;
91 buff[1] = 0x02;
92
93 hid_send_feature_report(hid, buff, 2); // Turn on Wireless
94
95 clear_buff(buff, 65);
96
97 buff[0] = 0x02;
98 buff[1] = 0x01;
99
100 hid_send_feature_report(hid, buff, 2); // Enables HMD
101
102 hid_close(hid);
103 hid_free_enumeration(dev);
104}