rifts-init.c
· 2.2 KiB · C
原始文件
#include <stdio.h>
#include <hidapi/hidapi.h>
#include <stdint.h>
#include <string.h>
// Build:
// gcc rifts-init.c -lhidapi-libusb -o rifts-init
void printBuffer(char *buff, int length) {
for (int i = 0; i < length; i++) {
printf("%02x ", buff[i] & 0xFF);
}
printf("\n");
}
void clear_buff(char *buff, int length) {
for (int i = 0; i < length; i++) {
buff[i] = 0x00;
}
}
int get_report(hid_device *hid, char id, char *buff, int length) {
buff[0] = id;
clear_buff(&buff[1], length-1);
return hid_get_feature_report(hid, buff, length);
}
typedef struct DeviceInfo {
char cmd;
uint16_t v_resolution;
uint16_t h_resolution;
uint16_t unk0;
char refreshRate;
int32_t unk1;
int32_t unk2;
int32_t unk3;
uint16_t unk4;
} __attribute__((aligned(1), packed));
int main() {
struct hid_device_info* dev = hid_enumerate(0x2833, 0x0051);
struct DeviceInfo devInfo;
if (dev == NULL) {
printf("Not found\n");
return 1;
}
struct hid_device_info *d = dev;
while (d != NULL) {
//printf("%d\n", d->interface_number);
if (d->interface_number == 0x07) {
printf("FOUND\n");
break;
}
d = d->next;
}
if (d == NULL) {
printf("Not found\n");
return 1;
}
hid_device *hid = hid_open_path(d->path);
if (hid == NULL) {
printf("FAIL %s\n", hid_error(hid));
return 1;
}
char buff[65];
int b = get_report(hid, 0x06, buff, 22);
memcpy(&devInfo, buff, 22);
printBuffer(buff, b);
clear_buff(buff, 65);
printf("%d\n", sizeof(devInfo));
printf("Horiz: %u\nVert: %u\nHz: %u\n", devInfo.h_resolution, devInfo.v_resolution, devInfo.refreshRate);
printf("Unk0: %u\nUnk1: %d\nUnk2: %d\nUnk3: %d\nUnk4: %u\n", devInfo.unk0, devInfo.unk1, devInfo.unk2, devInfo.unk3, devInfo.unk4);
clear_buff(buff, 65);
buff[0] = 0x14;
buff[1] = 0x01;
hid_send_feature_report(hid, buff, 2); // Enables Camera Device
clear_buff(buff, 65);
printf("Sending 0x0A 0x02\n");
buff[0] = 0x0A;
buff[1] = 0x02;
hid_send_feature_report(hid, buff, 2); // Turn on Wireless
clear_buff(buff, 65);
buff[0] = 0x02;
buff[1] = 0x01;
hid_send_feature_report(hid, buff, 2); // Enables HMD
hid_close(hid);
hid_free_enumeration(dev);
}
| 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 | |
| 9 | void 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 | |
| 17 | void clear_buff(char *buff, int length) { |
| 18 | for (int i = 0; i < length; i++) { |
| 19 | buff[i] = 0x00; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | int 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 | |
| 29 | typedef 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 | |
| 41 | int 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 | } |