chore: CRLF to LF

This commit is contained in:
smpn2
2022-12-16 23:18:35 +09:00
parent b7a60638a4
commit 6c914266d9
725 changed files with 131020 additions and 131020 deletions
+140 -140
View File
@@ -1,140 +1,140 @@
#include "lcdhandle.h"
#include "util/utils.h"
#include "util/time.h"
// globals
namespace games::shared {
// current state for easy access
bool LCD_ENABLED = false;
std::string LCD_CSM = "USER";
uint8_t LCD_BRI = 27;
uint8_t LCD_CON = 48;
uint8_t LCD_BL = 100;
uint8_t LCD_RED = 137;
uint8_t LCD_GREEN = 132;
uint8_t LCD_BLUE = 132;
}
void games::shared::LCDHandle::answer(std::string s) {
for (auto c : s) {
this->read_buffer.push_back((uint8_t) c);
}
this->read_buffer.push_back('\r');
this->read_buffer.push_back('\n');
}
bool games::shared::LCDHandle::open(LPCWSTR lpFileName) {
if (wcscmp(lpFileName, L"COM1")) {
return false;
}
log_info("lcdhandle", "opened COM1");
LCD_ENABLED = true;
return true;
}
int games::shared::LCDHandle::read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
// check time
if (get_system_milliseconds() < this->read_time_next) {
return 0;
}
// return buffer
if (read_buffer.size()) {
size_t write_count = MIN(nNumberOfBytesToRead, read_buffer.size());
memcpy(lpBuffer, &read_buffer[0], write_count);
read_buffer.erase(read_buffer.begin(), read_buffer.begin() + write_count);
return write_count;
}
// no data
return 0;
}
int games::shared::LCDHandle::write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) {
// check maximum size
if (nNumberOfBytesToWrite >= 256)
nNumberOfBytesToWrite = 255;
// get string
char data[256]{};
memcpy(data, lpBuffer, nNumberOfBytesToWrite);
std::string cmd_frame(data);
// check frame
if (string_begins_with(cmd_frame, "0")) {
// process frame
std::string cmd = cmd_frame.substr(1);
std::vector<std::string> cmd_split;
strsplit(cmd, cmd_split, ' ');
std::string param_in = "";
if (cmd_split.size() > 1) {
param_in = cmd_split[1];
if (string_ends_with(param_in.c_str(), "\r\n")) {
param_in = param_in.substr(0, param_in.size() - 2);
}
if (cmd_split.size() > 2) {
log_warning("lcdhandle", "too many parameters: {}", cmd_frame);
}
}
// get parameter
std::string param_out = "";
try {
if (string_begins_with(cmd_split[0], "MODEL?")) {
//param_out = "SPICE";
} else if (string_begins_with(cmd_split[0], "CSM")) {
LCD_CSM = param_in;
} else if (string_begins_with(cmd_split[0], "BRI")) {
LCD_BRI = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "CON")) {
LCD_CON = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "BL")) {
LCD_BL = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "RED")) {
LCD_RED = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "GREEN")) {
LCD_GREEN = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "BLUE")) {
LCD_BLUE = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "DFLIP")) {
// TODO
} else if (string_begins_with(cmd_split[0], "OFLIP")) {
// TODO
} else {
log_warning("lcdhandle", "unknown cmd: {}", cmd_frame);
}
} catch (std::invalid_argument&) {
log_warning("lcdhandle", "couldn't parse cmd: {}", cmd_frame);
}
// respond
answer(fmt::format("9{} {}", cmd_split[0], param_in));
answer(fmt::format("9OK {}", param_out));
// delay next read by 32ms
read_time_next = get_system_milliseconds() + 32;
}
// log unhandled commands
if (this->read_buffer.empty()) {
log_warning("lcdhandle", "unhandled cmd: {}", cmd_frame);
}
// return all bytes written
return (int) nNumberOfBytesToWrite;
}
int games::shared::LCDHandle::device_io(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize,
LPVOID lpOutBuffer, DWORD nOutBufferSize) {
return -1;
}
bool games::shared::LCDHandle::close() {
log_info("lcdhandle", "closed COM1");
LCD_ENABLED = false;
return true;
}
#include "lcdhandle.h"
#include "util/utils.h"
#include "util/time.h"
// globals
namespace games::shared {
// current state for easy access
bool LCD_ENABLED = false;
std::string LCD_CSM = "USER";
uint8_t LCD_BRI = 27;
uint8_t LCD_CON = 48;
uint8_t LCD_BL = 100;
uint8_t LCD_RED = 137;
uint8_t LCD_GREEN = 132;
uint8_t LCD_BLUE = 132;
}
void games::shared::LCDHandle::answer(std::string s) {
for (auto c : s) {
this->read_buffer.push_back((uint8_t) c);
}
this->read_buffer.push_back('\r');
this->read_buffer.push_back('\n');
}
bool games::shared::LCDHandle::open(LPCWSTR lpFileName) {
if (wcscmp(lpFileName, L"COM1")) {
return false;
}
log_info("lcdhandle", "opened COM1");
LCD_ENABLED = true;
return true;
}
int games::shared::LCDHandle::read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
// check time
if (get_system_milliseconds() < this->read_time_next) {
return 0;
}
// return buffer
if (read_buffer.size()) {
size_t write_count = MIN(nNumberOfBytesToRead, read_buffer.size());
memcpy(lpBuffer, &read_buffer[0], write_count);
read_buffer.erase(read_buffer.begin(), read_buffer.begin() + write_count);
return write_count;
}
// no data
return 0;
}
int games::shared::LCDHandle::write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) {
// check maximum size
if (nNumberOfBytesToWrite >= 256)
nNumberOfBytesToWrite = 255;
// get string
char data[256]{};
memcpy(data, lpBuffer, nNumberOfBytesToWrite);
std::string cmd_frame(data);
// check frame
if (string_begins_with(cmd_frame, "0")) {
// process frame
std::string cmd = cmd_frame.substr(1);
std::vector<std::string> cmd_split;
strsplit(cmd, cmd_split, ' ');
std::string param_in = "";
if (cmd_split.size() > 1) {
param_in = cmd_split[1];
if (string_ends_with(param_in.c_str(), "\r\n")) {
param_in = param_in.substr(0, param_in.size() - 2);
}
if (cmd_split.size() > 2) {
log_warning("lcdhandle", "too many parameters: {}", cmd_frame);
}
}
// get parameter
std::string param_out = "";
try {
if (string_begins_with(cmd_split[0], "MODEL?")) {
//param_out = "SPICE";
} else if (string_begins_with(cmd_split[0], "CSM")) {
LCD_CSM = param_in;
} else if (string_begins_with(cmd_split[0], "BRI")) {
LCD_BRI = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "CON")) {
LCD_CON = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "BL")) {
LCD_BL = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "RED")) {
LCD_RED = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "GREEN")) {
LCD_GREEN = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "BLUE")) {
LCD_BLUE = std::stoi(param_in);
} else if (string_begins_with(cmd_split[0], "DFLIP")) {
// TODO
} else if (string_begins_with(cmd_split[0], "OFLIP")) {
// TODO
} else {
log_warning("lcdhandle", "unknown cmd: {}", cmd_frame);
}
} catch (std::invalid_argument&) {
log_warning("lcdhandle", "couldn't parse cmd: {}", cmd_frame);
}
// respond
answer(fmt::format("9{} {}", cmd_split[0], param_in));
answer(fmt::format("9OK {}", param_out));
// delay next read by 32ms
read_time_next = get_system_milliseconds() + 32;
}
// log unhandled commands
if (this->read_buffer.empty()) {
log_warning("lcdhandle", "unhandled cmd: {}", cmd_frame);
}
// return all bytes written
return (int) nNumberOfBytesToWrite;
}
int games::shared::LCDHandle::device_io(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize,
LPVOID lpOutBuffer, DWORD nOutBufferSize) {
return -1;
}
bool games::shared::LCDHandle::close() {
log_info("lcdhandle", "closed COM1");
LCD_ENABLED = false;
return true;
}
+39 -39
View File
@@ -1,39 +1,39 @@
#pragma once
#include <vector>
#include <windows.h>
#include "util/logging.h"
#include "hooks/devicehook.h"
namespace games::shared {
// current state for easy access
extern bool LCD_ENABLED;
extern std::string LCD_CSM;
extern uint8_t LCD_BRI;
extern uint8_t LCD_CON;
extern uint8_t LCD_BL;
extern uint8_t LCD_RED;
extern uint8_t LCD_GREEN;
extern uint8_t LCD_BLUE;
class LCDHandle : public CustomHandle {
private:
std::vector<uint8_t> read_buffer;
uint64_t read_time_next = 0;
void answer(std::string s);
public:
bool open(LPCWSTR lpFileName) override;
int read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) override;
int write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) override;
int device_io(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer,
DWORD nOutBufferSize) override;
bool close() override;
};
}
#pragma once
#include <vector>
#include <windows.h>
#include "util/logging.h"
#include "hooks/devicehook.h"
namespace games::shared {
// current state for easy access
extern bool LCD_ENABLED;
extern std::string LCD_CSM;
extern uint8_t LCD_BRI;
extern uint8_t LCD_CON;
extern uint8_t LCD_BL;
extern uint8_t LCD_RED;
extern uint8_t LCD_GREEN;
extern uint8_t LCD_BLUE;
class LCDHandle : public CustomHandle {
private:
std::vector<uint8_t> read_buffer;
uint64_t read_time_next = 0;
void answer(std::string s);
public:
bool open(LPCWSTR lpFileName) override;
int read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) override;
int write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) override;
int device_io(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer,
DWORD nOutBufferSize) override;
bool close() override;
};
}
+609 -609
View File
File diff suppressed because it is too large Load Diff
+18 -18
View File
@@ -1,18 +1,18 @@
#pragma once
#include <vector>
#include <string>
#include <windows.h>
namespace games::shared {
// settings
extern std::vector<std::string> PRINTER_PATH;
extern std::vector<std::string> PRINTER_FORMAT;
extern int PRINTER_JPG_QUALITY;
extern bool PRINTER_CLEAR;
extern bool PRINTER_OVERWRITE_FILE;
void printer_attach();
}
#pragma once
#include <vector>
#include <string>
#include <windows.h>
namespace games::shared {
// settings
extern std::vector<std::string> PRINTER_PATH;
extern std::vector<std::string> PRINTER_FORMAT;
extern int PRINTER_JPG_QUALITY;
extern bool PRINTER_CLEAR;
extern bool PRINTER_OVERWRITE_FILE;
void printer_attach();
}
+150 -150
View File
@@ -1,150 +1,150 @@
#include "twtouch.h"
#include "util/utils.h"
namespace games::shared {
#pragma pack(push, 1)
struct TwTouchEventReport {
uint32_t type;
uint8_t padding1[8];
uint32_t status;
uint16_t x;
uint16_t y;
uint8_t padding2[4];
};
static_assert(sizeof(TwTouchEventReport) == 0x18);
#pragma pack(pop)
bool TwTouchDevice::open(LPCWSTR lpFileName) {
return wcscmp(lpFileName, L"\\\\.\\TwTouchDriver") == 0;
}
int TwTouchDevice::read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
// ignore if buffer is too small
if (nNumberOfBytesToRead < sizeof(TwTouchEventReport)) {
return 0;
}
// get touch events once our buffer is empty
if (this->report_buffer.empty()) {
touch_get_events(this->report_buffer);
}
// check if an event is available
if (this->report_buffer.empty()) {
/*
* We limit the number of continuous reads the device can do
* since games may try to read all at once into a buffer.
* QMA has a limit of 100 events going in at once.
* To avoid this we have to return nothing at least once every 100 read calls.
*/
if (this->continuous_reads >= 99) {
// reset counter
this->continuous_reads = 0;
} else {
// get touch points
touch_get_points(this->touch_points);
// insert fake events
for (auto &touch_point : this->touch_points) {
this->report_buffer.push_back(TouchEvent {
.id = touch_point.id,
.x = touch_point.x,
.y = touch_point.y,
.type = TOUCH_MOVE,
.mouse = false,
});
}
// clear touch points
this->touch_points.clear();
}
} else {
// increase counter
this->continuous_reads++;
// pick the first event
auto &touch_event = this->report_buffer[0];
// build report
TwTouchEventReport report {};
/*
* Known report types
*
* ID Size Desc
* 0x01 20
* 0x02 16
* 0x03 20 QMA checks uint32_t at offset 12 and uint16_t at offset 16
* 0x04 16
* 0x05 24 Touch Event
* 0x06 24
* 0x08 24
* 0x09 24 SCV has an alternate Touch Event path here
* 0x0B 32
* 0x0C 16
* 0x0D 36
* 0x0E 16
*/
report.type = 0x05;
// set report data
switch (touch_event.type) {
case TOUCH_DOWN:
case TOUCH_MOVE:
// if the status is 1 it means it's pressed
report.status = 1;
report.x = CLAMP(this->offset_x + touch_event.x * this->scale_x, 0, 65535);
report.y = CLAMP(this->offset_y + touch_event.y * this->scale_y, 0, 65535);
// flip coordinates
if (this->flip_x) {
report.x = 0xFFFF - report.x;
}
if (this->flip_y) {
report.y = 0xFFFF - report.y;
}
break;
case TOUCH_UP:
// status 3 (and 12?) is a touch up event
report.status = 3;
report.x = 0;
report.y = 0;
break;
}
// erase touch event
this->report_buffer.erase(this->report_buffer.begin());
// copy report to buffer
memcpy(lpBuffer, &report, sizeof(report));
return sizeof(report);
}
// no touch event available for read
return 0;
}
int TwTouchDevice::write(LPCVOID, DWORD) {
return 0;
}
int TwTouchDevice::device_io(DWORD, LPVOID, DWORD, LPVOID, DWORD) {
return 0;
}
bool TwTouchDevice::close() {
return true;
}
}
#include "twtouch.h"
#include "util/utils.h"
namespace games::shared {
#pragma pack(push, 1)
struct TwTouchEventReport {
uint32_t type;
uint8_t padding1[8];
uint32_t status;
uint16_t x;
uint16_t y;
uint8_t padding2[4];
};
static_assert(sizeof(TwTouchEventReport) == 0x18);
#pragma pack(pop)
bool TwTouchDevice::open(LPCWSTR lpFileName) {
return wcscmp(lpFileName, L"\\\\.\\TwTouchDriver") == 0;
}
int TwTouchDevice::read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) {
// ignore if buffer is too small
if (nNumberOfBytesToRead < sizeof(TwTouchEventReport)) {
return 0;
}
// get touch events once our buffer is empty
if (this->report_buffer.empty()) {
touch_get_events(this->report_buffer);
}
// check if an event is available
if (this->report_buffer.empty()) {
/*
* We limit the number of continuous reads the device can do
* since games may try to read all at once into a buffer.
* QMA has a limit of 100 events going in at once.
* To avoid this we have to return nothing at least once every 100 read calls.
*/
if (this->continuous_reads >= 99) {
// reset counter
this->continuous_reads = 0;
} else {
// get touch points
touch_get_points(this->touch_points);
// insert fake events
for (auto &touch_point : this->touch_points) {
this->report_buffer.push_back(TouchEvent {
.id = touch_point.id,
.x = touch_point.x,
.y = touch_point.y,
.type = TOUCH_MOVE,
.mouse = false,
});
}
// clear touch points
this->touch_points.clear();
}
} else {
// increase counter
this->continuous_reads++;
// pick the first event
auto &touch_event = this->report_buffer[0];
// build report
TwTouchEventReport report {};
/*
* Known report types
*
* ID Size Desc
* 0x01 20
* 0x02 16
* 0x03 20 QMA checks uint32_t at offset 12 and uint16_t at offset 16
* 0x04 16
* 0x05 24 Touch Event
* 0x06 24
* 0x08 24
* 0x09 24 SCV has an alternate Touch Event path here
* 0x0B 32
* 0x0C 16
* 0x0D 36
* 0x0E 16
*/
report.type = 0x05;
// set report data
switch (touch_event.type) {
case TOUCH_DOWN:
case TOUCH_MOVE:
// if the status is 1 it means it's pressed
report.status = 1;
report.x = CLAMP(this->offset_x + touch_event.x * this->scale_x, 0, 65535);
report.y = CLAMP(this->offset_y + touch_event.y * this->scale_y, 0, 65535);
// flip coordinates
if (this->flip_x) {
report.x = 0xFFFF - report.x;
}
if (this->flip_y) {
report.y = 0xFFFF - report.y;
}
break;
case TOUCH_UP:
// status 3 (and 12?) is a touch up event
report.status = 3;
report.x = 0;
report.y = 0;
break;
}
// erase touch event
this->report_buffer.erase(this->report_buffer.begin());
// copy report to buffer
memcpy(lpBuffer, &report, sizeof(report));
return sizeof(report);
}
// no touch event available for read
return 0;
}
int TwTouchDevice::write(LPCVOID, DWORD) {
return 0;
}
int TwTouchDevice::device_io(DWORD, LPVOID, DWORD, LPVOID, DWORD) {
return 0;
}
bool TwTouchDevice::close() {
return true;
}
}
+36 -36
View File
@@ -1,36 +1,36 @@
#pragma once
#include <cstdint>
#include <vector>
#include "hooks/devicehook.h"
#include "touch/touch.h"
namespace games::shared {
class TwTouchDevice : public CustomHandle {
private:
// report buffer
std::vector<TouchEvent> report_buffer;
std::vector<TouchPoint> touch_points;
unsigned int continuous_reads = 0;
public:
// settings
float offset_x = 0.f;
float offset_y = 0.f;
float scale_x = 1.f;
float scale_y = 1.f;
bool flip_x = false;
bool flip_y = false;
// overrides
bool open(LPCWSTR lpFileName) override;
int read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) override;
int write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) override;
int device_io(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer,
DWORD nOutBufferSize) override;
bool close() override;
};
}
#pragma once
#include <cstdint>
#include <vector>
#include "hooks/devicehook.h"
#include "touch/touch.h"
namespace games::shared {
class TwTouchDevice : public CustomHandle {
private:
// report buffer
std::vector<TouchEvent> report_buffer;
std::vector<TouchPoint> touch_points;
unsigned int continuous_reads = 0;
public:
// settings
float offset_x = 0.f;
float offset_y = 0.f;
float scale_x = 1.f;
float scale_y = 1.f;
bool flip_x = false;
bool flip_y = false;
// overrides
bool open(LPCWSTR lpFileName) override;
int read(LPVOID lpBuffer, DWORD nNumberOfBytesToRead) override;
int write(LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite) override;
int device_io(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer,
DWORD nOutBufferSize) override;
bool close() override;
};
}