From cf6a189733fe2ab773c25d6e9433294c0b6e4142 Mon Sep 17 00:00:00 2001 From: Dniel97 Date: Mon, 25 Dec 2023 16:20:04 +0100 Subject: [PATCH] Updated segatools --- CMakeLists.txt | 27 -- README.md | 14 +- {segatools/aimeio => aimeio}/aimeio.c | 67 ++- aimeio/aimeio.def | 9 + {segatools/chuniio => chuniio}/chuniio.c | 30 +- chuniio/chuniio.def | 13 + src/defer.h | 10 - src/main.cpp | 549 ----------------------- src/resources.rc | 36 -- src/socket.h | 42 -- src/struct.h | 84 ---- src/version.h | 10 - 12 files changed, 115 insertions(+), 776 deletions(-) delete mode 100644 CMakeLists.txt rename {segatools/aimeio => aimeio}/aimeio.c (83%) create mode 100644 aimeio/aimeio.def rename {segatools/chuniio => chuniio}/chuniio.c (85%) create mode 100644 chuniio/chuniio.def delete mode 100644 src/defer.h delete mode 100644 src/main.cpp delete mode 100644 src/resources.rc delete mode 100644 src/socket.h delete mode 100644 src/struct.h delete mode 100644 src/version.h diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 843882e..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -project(brokenithm LANGUAGES CXX) -cmake_minimum_required(VERSION 3.4) -SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") -INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include/") -IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE Release) -ENDIF() -SET(CMAKE_CXX_STANDARD 17) - -IF (NOT WIN32) - MESSAGE(FATAL_ERROR "This is not supposed to be run on non-Windows platforms!") -ENDIF() - - -IF (NOT MSVC) - ADD_COMPILE_OPTIONS(-Wall -Wextra -Wno-unused-parameter -Wno-unused-result) -ELSE() - ADD_COMPILE_OPTIONS(/W4) -ENDIF() - -ADD_EXECUTABLE(brokenithm - src/main.cpp - src/resources.rc) -INCLUDE_DIRECTORIES(src) -LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}) - -TARGET_LINK_LIBRARIES(brokenithm ws2_32) diff --git a/README.md b/README.md index 84d2c66..c3d4b1c 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,4 @@ -## Brokenithm-Android-Server - -The Windows server of [Brokenithm-Android](https://github.com/tindy2013/Brokenithm-Android). - -# Build - -```bash -# Only tested with MSYS2 with MinGW -cmake -G "MSYS Makefiles" . -make -``` +## Brokenithm-Evolved segatools modification +This branch only contains modified files from my [segatools](https://gitea.tendokyu.moe/Dniel97/segatools/src/branch/chuniio) repo. +And will not contain other files. diff --git a/segatools/aimeio/aimeio.c b/aimeio/aimeio.c similarity index 83% rename from segatools/aimeio/aimeio.c rename to aimeio/aimeio.c index 67e6881..2ed711a 100644 --- a/segatools/aimeio/aimeio.c +++ b/aimeio/aimeio.c @@ -17,6 +17,7 @@ struct aime_io_config { wchar_t aime_path[MAX_PATH]; wchar_t felica_path[MAX_PATH]; bool felica_gen; + bool aime_gen; uint8_t vk_scan; }; @@ -99,10 +100,17 @@ static void aime_io_config_read( cfg->felica_path, _countof(cfg->felica_path), filename); + dprintf("NFC: felicaPath GetLastError %lx\n", GetLastError()); cfg->felica_gen = GetPrivateProfileIntW( L"aime", L"felicaGen", + 0, + filename); + + cfg->aime_gen = GetPrivateProfileIntW( + L"aime", + L"aimeGen", 1, filename); @@ -199,6 +207,47 @@ static HRESULT aime_io_generate_felica( return S_OK; } +static HRESULT aime_io_generate_aime( + const wchar_t *path, + uint8_t *bytes, + size_t nbytes) +{ + size_t i; + FILE *f; + + assert(path != NULL); + assert(bytes != NULL); + assert(nbytes > 0); + + srand(time(NULL)); + + /* AiMe IDs should not start with 3, due to a missing check for BananaPass IDs */ + do { + for (i = 0; i < nbytes; i++) { + bytes[i] = rand() % 10 << 4 | rand() % 10; + } + } while (bytes[0] >> 4 == 3); + + f = _wfopen(path, L"w"); + + if (f == NULL) { + dprintf("AimeIO DLL: %S: fopen failed: %i\n", path, (int) errno); + + return E_FAIL; + } + + for (i = 0; i < nbytes; i++) { + fprintf(f, "%02x", bytes[i]); + } + + fprintf(f, "\n"); + fclose(f); + + dprintf("AimeIO DLL: Generated random AiMe ID\n"); + + return S_OK; +} + uint16_t aime_io_get_api_version(void) { return 0x0100; @@ -269,6 +318,22 @@ HRESULT aime_io_nfc_poll(uint8_t unit_no) return S_OK; } + /* Try generating AiMe IC (if enabled) */ + + if (aime_io_cfg.aime_gen) { + hr = aime_io_generate_aime( + aime_io_cfg.aime_path, + aime_io_aime_id, + sizeof(aime_io_aime_id)); + + if (FAILED(hr)) { + return hr; + } + + aime_io_aime_id_present = true; + return S_OK; + } + /* Try FeliCa IC */ hr = aime_io_read_id_file( @@ -340,4 +405,4 @@ HRESULT aime_io_nfc_get_felica_id(uint8_t unit_no, uint64_t *IDm) } void aime_io_led_set_color(uint8_t unit_no, uint8_t r, uint8_t g, uint8_t b) -{} \ No newline at end of file +{} diff --git a/aimeio/aimeio.def b/aimeio/aimeio.def new file mode 100644 index 0000000..9b88247 --- /dev/null +++ b/aimeio/aimeio.def @@ -0,0 +1,9 @@ +LIBRARY aimeio + +EXPORTS + aime_io_get_api_version + aime_io_init + aime_io_nfc_poll + aime_io_nfc_get_aime_id + aime_io_nfc_get_felica_id + aime_io_led_set_color diff --git a/segatools/chuniio/chuniio.c b/chuniio/chuniio.c similarity index 85% rename from segatools/chuniio/chuniio.c rename to chuniio/chuniio.c index ce921e1..79c0f1e 100644 --- a/segatools/chuniio/chuniio.c +++ b/chuniio/chuniio.c @@ -55,7 +55,7 @@ void chuni_io_init_shared_memory() uint16_t chuni_io_get_api_version(void) { - return 0x0101; + return 0x0102; } HRESULT chuni_io_jvs_init(void) @@ -95,14 +95,14 @@ void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams) size_t i; if ((chuni_io_file_mapping && chuni_io_file_mapping->testBtn) || GetAsyncKeyState(chuni_io_cfg.vk_test)) { - *opbtn |= 0x01; /* Test */ + *opbtn |= CHUNI_IO_OPBTN_TEST; /* Test */ } if ((chuni_io_file_mapping && chuni_io_file_mapping->serviceBtn) || GetAsyncKeyState(chuni_io_cfg.vk_service)) { - *opbtn |= 0x02; /* Service */ + *opbtn |= CHUNI_IO_OPBTN_SERVICE; /* Service */ } - if (GetAsyncKeyState(chuni_io_cfg.vk_ir)) { + if (GetAsyncKeyState(chuni_io_cfg.vk_ir_emu)) { if (chuni_io_hand_pos < 6) { chuni_io_hand_pos++; } @@ -113,10 +113,18 @@ void chuni_io_jvs_poll(uint8_t *opbtn, uint8_t *beams) } for (i = 0 ; i < 6 ; i++) { - if ((chuni_io_file_mapping && chuni_io_file_mapping->airIoStatus[i]) || chuni_io_hand_pos > i) { + if (chuni_io_hand_pos > i) { *beams |= (1 << i); } } + + // IR format is beams[5:0] = {b5,b6,b3,b4,b1,b2}; + for (i = 0 ; i < 3 ; i++) { + if (chuni_io_file_mapping && chuni_io_file_mapping->airIoStatus[i*2]) + *beams |= (1 << (i*2+1)); + if (chuni_io_file_mapping && chuni_io_file_mapping->airIoStatus[i*2+1]) + *beams |= (1 << (i*2)); + } } HRESULT chuni_io_slider_init(void) @@ -177,4 +185,14 @@ static unsigned int __stdcall chuni_io_slider_thread_proc(void *ctx) } return 0; -} \ No newline at end of file +} + +HRESULT chuni_io_led_init(void) +{ + return S_OK; +} + +void chuni_io_led_set_colors(uint8_t board, uint8_t *rgb) +{ + return; +} diff --git a/chuniio/chuniio.def b/chuniio/chuniio.def new file mode 100644 index 0000000..27de193 --- /dev/null +++ b/chuniio/chuniio.def @@ -0,0 +1,13 @@ +LIBRARY chuniio + +EXPORTS + chuni_io_get_api_version + chuni_io_jvs_init + chuni_io_jvs_poll + chuni_io_jvs_read_coin_counter + chuni_io_slider_init + chuni_io_slider_set_leds + chuni_io_slider_start + chuni_io_slider_stop + chuni_io_led_init + chuni_io_led_set_colors diff --git a/src/defer.h b/src/defer.h deleted file mode 100644 index 8add830..0000000 --- a/src/defer.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef DEFER_H_INCLUDED -#define DEFER_H_INCLUDED - -#define CONCAT(a,b) a ## b -#define DO_CONCAT(a,b) CONCAT(a,b) -template class __defer_struct final {private: T fn; bool __cancelled = false; public: explicit __defer_struct(T func) : fn(std::move(func)) {} ~__defer_struct() {if(!__cancelled) fn();} void cancel() {__cancelled = true;} }; -//#define defer(x) std::unique_ptr DO_CONCAT(__defer_deleter_,__LINE__) (nullptr, [&](...){x}); -#define defer(x) __defer_struct DO_CONCAT(__defer_deleter,__LINE__) ([&](...){x;}); - -#endif // DEFER_H_INCLUDED diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index 22fa251..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,549 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "socket.h" -#include "defer.h" -#include "version.h" -#include "struct.h" -#include - -std::string remote_address; -uint16_t remote_port = 52468; -uint16_t server_port = 52468; -bool tcp_mode = false; - -size_t tcp_buffer_size = 96; -size_t tcp_receive_threshold = 48; - -std::atomic_bool EXIT_FLAG {false}, CONNECTED {false}; - -void socketSetTimeout(SOCKET sHost, int timeout) -{ - setsockopt(sHost, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(int)); - setsockopt(sHost, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(int)); -} - -int socketBind(SOCKET sHost, long addr, uint16_t port) -{ - sockaddr_in srcaddr = {}; - memset(&srcaddr, 0, sizeof(srcaddr)); - srcaddr.sin_family = AF_INET; - srcaddr.sin_addr.s_addr = addr; - srcaddr.sin_port = htons(port); - return bind(sHost, reinterpret_cast(&srcaddr), sizeof(srcaddr)); -} - -sockaddr_in makeBroadcastAddr(uint16_t port) -{ - struct sockaddr_in addr = {}; - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = htonl(INADDR_BROADCAST); - addr.sin_port = htons(port); - return addr; -} - -sockaddr_in makeIPv4Addr(const std::string &host, uint16_t port) -{ - struct sockaddr_in addr = {}; - addr.sin_family = AF_INET; - inet_pton(AF_INET, host.data(), (struct in_addr *)&addr.sin_addr.s_addr); - addr.sin_port = htons(port); - return addr; -} - -int socketSendTo(SOCKET sHost, const sockaddr_in &addr, const std::string &data) -{ - return sendto(sHost, data.data(), data.size(), 0, reinterpret_cast(&addr), sizeof(addr)); -} - -std::string getTime(int type) -{ - time_t lt; - char tmpbuf[32], cMillis[7]; - std::string format; - timeval tv; - gettimeofday(&tv, NULL); - snprintf(cMillis, 7, "%.6ld", (long)tv.tv_usec); - lt = time(NULL); - struct tm *local = localtime(<); - switch(type) - { - case 1: - format = "%Y%m%d-%H%M%S"; - break; - case 2: - format = "%Y/%m/%d %a %H:%M:%S." + std::string(cMillis); - break; - case 3: - format = "%Y-%m-%d %H:%M:%S"; - break; - } - strftime(tmpbuf, 32, format.data(), local); - return std::string(tmpbuf); -} - -template -void printErr(const char* format, Args... args) -{ - std::string time = "[" + getTime(2) + "] "; - fprintf(stderr, time.data()); - fprintf(stderr, format, args...); -} - -void threadLEDBroadcast(SOCKET sHost, const IPCMemoryInfo* memory) -{ - static std::string previous_status; - static int skip_count = 0; - static std::string head = "\x63LED"; - auto addr = makeIPv4Addr(remote_address, remote_port); - while(!EXIT_FLAG) - { - if(!CONNECTED) { - Sleep(50); - continue; - } - std::string current_status; - current_status.assign(reinterpret_cast(memory->ledRgbData), sizeof(memory->ledRgbData)); - bool same = true; - if(!previous_status.empty()) - { - same = (memcmp(previous_status.data(), current_status.data(), previous_status.size()) == 0); - } - else - same = false; - previous_status = current_status; - if(!same) - { - current_status.insert(0, head); - if(socketSendTo(sHost, addr, current_status) < 0) - { - printErr("[Error] Cannot send packet: error %lu\n", GetLastError()); - if(tcp_mode) - { - if(errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) - { - continue; - } - else - { - printErr("[INFO] Device disconnected!\n"); - CONNECTED = false; - EXIT_FLAG = true; - break; - } - } - } - skip_count = 0; - } - else - { - if(++skip_count > 50) - { - current_status.insert(0, head); - if(socketSendTo(sHost, addr, current_status) < 0) - { - printErr("[ERROR] Cannot send packet: error %lu\n", GetLastError()); - if(tcp_mode) - { - if(errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) - { - continue; - } - else - { - printErr("[INFO] Device disconnected!\n"); - CONNECTED = false; - EXIT_FLAG = true; - break; - } - } - } - skip_count = 0; - } - } - Sleep(10); - } -} - -enum -{ - FUNCTION_COIN = 1, - FUNCTION_CARD -}; - -void getSocksAddress(const PacketConnect* pkt, std::string &address, uint16_t &port) -{ - char cAddr[128] = {}; - std::string retAddr; - int family = pkt->addrType; - port = ntohs(pkt->port); - switch(family) - { - case 1: //IPv4 - inet_ntop(AF_INET, pkt->addr.addr4.addr, cAddr, 127); - break; - case 2: //IPv6 - inet_ntop(AF_INET6, pkt->addr.addr6, cAddr, 127); - break; - } - address.assign(cAddr); -} - -uint32_t last_input_packet_id = 0; - -void updatePacketId(uint32_t newPacketId) -{ - if(last_input_packet_id > newPacketId) - { - printErr("[WARN] Packet #%" PRIu32 " came too late\n", newPacketId); - } - else if(newPacketId > last_input_packet_id + 1) - { - printErr("[WARN] Packets between #%" PRIu32 " and #%" PRIu32 " total %" PRIu32 " packet(s) are missing, probably too late or dropped\n", last_input_packet_id, newPacketId, newPacketId - last_input_packet_id - 1); - } - else if(newPacketId == last_input_packet_id) - { - printErr("[WARN] Packet #%" PRIu32 " duplicated\n", newPacketId); - } - last_input_packet_id = newPacketId; -} - -template -void dprintf(const char* format, Args... args) -{ - fprintf(stderr, format, args...); -} - -void dump(const void *ptr, size_t nbytes, bool hex_string = false) -{ - const uint8_t *bytes; - uint8_t c; - size_t i; - size_t j; - - if (nbytes == 0) { - dprintf("\t--- Empty ---\n"); - } - - bytes = (const unsigned char*)ptr; - - if (hex_string) { - for (i = 0 ; i < nbytes ; i++) { - dprintf("%02x", bytes[i]); - } - dprintf("\n"); - return; - } - - for (i = 0 ; i < nbytes ; i += 16) { - dprintf(" %08x:", (int) i); - - for (j = 0 ; i + j < nbytes && j < 16 ; j++) { - dprintf(" %02x", bytes[i + j]); - } - - while (j < 16) { - dprintf(" "); - j++; - } - - dprintf(" "); - - for (j = 0 ; i + j < nbytes && j < 16 ; j++) { - c = bytes[i + j]; - - if (c < 0x20 || c >= 0x7F) { - c = '.'; - } - - dprintf("%c", c); - } - - dprintf("\n"); - } - - dprintf("\n"); -} - -enum -{ - CARD_AIME, - CARD_FELICA -}; - -void printCardInfo(uint8_t cardType, uint8_t *cardId) -{ - switch(cardType) - { - case CARD_AIME: - printErr("[INFO] Card Type: Aime\t\tID: "); - dump(cardId, 10, true); - break; - case CARD_FELICA: - printErr("[INFO] Card Type: FeliCa\tIDm: "); - dump(cardId, 8, true); - break; - } -} - -void threadInputReceive(SOCKET sHost, IPCMemoryInfo *memory) -{ - char recv_buffer[tcp_buffer_size]; - char buffer[BUFSIZ]; - std::string remains; - auto addr = makeIPv4Addr(remote_address, remote_port); - while(!EXIT_FLAG) - { - int recv_len, real_len; - size_t packet_len; - uint32_t current_packet_id; - if(!tcp_mode) - { - /** - on UDP mode data is sent as packets, so just receive into a buffer big enough for 1 packet - each recvfrom call will only get 1 packet of data, the remaining data is discarded - **/ - - if((recv_len = recvfrom(sHost, buffer, BUFSIZ - 1, 0, NULL, NULL)) == -1) - continue; - real_len = buffer[0]; - if(real_len > recv_len) - continue; - packet_len = real_len + 1; - } - else - { - /** - on TCP mode data is sent as stream, one recvfrom call may receive multiple packets - so we need to store the remaining data when real_len > recv_len - **/ - if(remains.size() < tcp_receive_threshold) - { - if((recv_len = recv(sHost, recv_buffer, tcp_buffer_size - 1, 0)) == -1) - continue; - remains.append(recv_buffer, recv_len); - } - - int data_left = remains.size(); - real_len = remains[0]; - if(real_len > data_left) - continue; - packet_len = real_len + 1; - memcpy(buffer, remains.data(), packet_len); - remains.erase(0, packet_len); - } - - if(packet_len >= sizeof(PacketInput) && buffer[1] == 'I' && buffer[2] == 'N' && buffer[3] == 'P') - { - PacketInput *pkt = reinterpret_cast(buffer); - memcpy(memory->airIoStatus, pkt->airIoStatus, sizeof(pkt->airIoStatus)); - memcpy(memory->sliderIoStatus, pkt->sliderIoStatus, sizeof(pkt->sliderIoStatus)); - memory->testBtn = pkt->testBtn; - memory->serviceBtn = pkt->serviceBtn; - current_packet_id = ntohl(pkt->packetId); - updatePacketId(current_packet_id); - } - else if(packet_len >= sizeof(PacketInputNoAir) && buffer[1] == 'I' && buffer[2] == 'P' && buffer[3] == 'T') /// without air block - { - PacketInputNoAir *pkt = reinterpret_cast(buffer); - memcpy(memory->sliderIoStatus, pkt->sliderIoStatus, sizeof(pkt->sliderIoStatus)); - memory->testBtn = pkt->testBtn; - memory->serviceBtn = pkt->serviceBtn; - current_packet_id = ntohl(pkt->packetId); - updatePacketId(current_packet_id); - } - else if(packet_len >= sizeof(PacketFunction) && buffer[1] == 'F' && buffer[2] == 'N' && buffer[3] == 'C') - { - PacketFunction *pkt = reinterpret_cast(buffer); - switch(pkt->funcBtn) - { - case FUNCTION_COIN: - memory->coinInsertion = 1; - break; - case FUNCTION_CARD: - memory->cardRead = 1; - break; - } - } - else if(packet_len >= sizeof(PacketConnect) && buffer[1] == 'C' && buffer[2] == 'O' && buffer[3] == 'N') - { - last_input_packet_id = 0; - PacketConnect *pkt = reinterpret_cast(buffer); - getSocksAddress(pkt, remote_address, remote_port); - printErr("[INFO] Device %s:%d connected.\n", remote_address.data(), remote_port); - CONNECTED = true; - } - else if(packet_len >= 4 && buffer[1] == 'D' && buffer[2] == 'I' && buffer[3] == 'S') - { - CONNECTED = false; - if(tcp_mode) - { - EXIT_FLAG = true; - printErr("[INFO] Device disconnected!\n"); - break; - } - if(!remote_address.empty()) - { - printErr("[INFO] Device %s:%d disconnected.\n", remote_address.data(), remote_port); - remote_address.clear(); - } - } - else if(packet_len >= sizeof(PacketPing) && buffer[1] == 'P' && buffer[2] == 'I' && buffer[3] == 'N') - { - if(!CONNECTED) - continue; - std::string response; - response.assign(buffer, 12); - response.replace(2, 1, "O"); - socketSendTo(sHost, addr, response); - } - else if(packet_len >= sizeof(PacketCard) && buffer[1] == 'C' && buffer[2] == 'R' && buffer[3] == 'D') - { - PacketCard *pkt = reinterpret_cast(buffer); - static uint8_t lastId[10] = {}; - if(pkt->remoteCardRead) - { - if(memcmp(lastId, pkt->remoteCardId, 10)) - { - printErr("[INFO] Got remote card.\n"); - printCardInfo(pkt->remoteCardType, pkt->remoteCardId); - memcpy(lastId, pkt->remoteCardId, 10); - } - } - else - { - if(memory->remoteCardRead) - { - printErr("[INFO] Remote card removed.\n"); - memset(lastId, 0, 10); - } - } - memory->remoteCardRead = pkt->remoteCardRead; - memory->remoteCardType = pkt->remoteCardType; - memcpy(memory->remoteCardId, pkt->remoteCardId, 10); - } - } -} - -void printInfo() -{ - printf("=================================================\n"); - printf("= Brokenithm-Evolved-Android: =\n"); - printf("= Brokenithm with full IO over network =\n"); - printf("= " VERSION " by XTindy =\n"); - printf("= Original: esterTion =\n"); - printf("=================================================\n\n"); -} - -void checkArgs(int argc, char* argv[]) -{ - int opt; - while((opt = getopt(argc, argv, "p:Tr:")) != -1) - { - switch(opt) - { - case 'p': - server_port = atoi(optarg); - break; - case 'T': - tcp_mode = true; - break; - case 'r': - tcp_receive_threshold = atoi(optarg); - tcp_buffer_size = tcp_receive_threshold * 2; - break; - } - } -} - -int main(int argc, char* argv[]) -{ - checkArgs(argc, argv); - SetConsoleTitle("Brokenithm-Evolved-Android Server"); - printInfo(); - - WSAData wsaData; - if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) - { - //std::cerr << "WSA startup failed!\n"; - printErr("[ERROR] WSA startup failed!\n"); - return -1; - } - const char *memFileName = "Local\\BROKENITHM_SHARED_BUFFER"; - HANDLE hMapFile = OpenFileMappingA(FILE_MAP_ALL_ACCESS, false, memFileName); - if(hMapFile == NULL) - { - hMapFile = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, 1024, memFileName); - if(hMapFile == NULL) - { - //std::cerr << "CreateFileMapping failed! Error " + std::to_string(GetLastError()); - printErr("[ERROR] CreateFileMapping failed! error: %lu\n", GetLastError()); - return -1; - } - } - defer(CloseHandle(hMapFile)) - IPCMemoryInfo *memory = reinterpret_cast(MapViewOfFileEx(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 1024, NULL)); - if(memory == nullptr) - { - //std::cerr << "Cannot get view of memory map! Error " + std::to_string(GetLastError()); - printErr("[ERROR] Cannot get view of memory map! error: %lu\n", GetLastError()); - return -1; - } - if(!tcp_mode) - { - printErr("[INFO] Mode: UDP\n"); - SOCKET sHost = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - defer(closesocket(sHost)) - socketSetTimeout(sHost, 2000); - socketBind(sHost, htonl(INADDR_ANY), server_port); - printErr("[INFO] Waiting for device on port %d...\n", server_port); - auto LEDThread = std::thread(threadLEDBroadcast, sHost, memory); - auto InputThread = std::thread(threadInputReceive, sHost, memory); - while(_getwch() != L'q'); - printErr("[INFO] Exiting gracefully...\n"); - last_input_packet_id = 0; - EXIT_FLAG = true; - LEDThread.join(); - InputThread.join(); - } - else - { - printErr("[INFO] Mode: TCP\n"); - printErr("[INFO] TCP receive buffer size: %" PRIu32 "\n", tcp_buffer_size); - printErr("[INFO] TCP receive threshold: %" PRIu32 "\n", tcp_receive_threshold); - SOCKET sHost = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - defer(closesocket(sHost)); - socketSetTimeout(sHost, 50); - socketBind(sHost, htonl(INADDR_ANY), server_port); - listen(sHost, 10); - while(true) - { - printErr("[INFO] Waiting for device on port %d...\n", server_port); - struct sockaddr_in user_socket = {}; - socklen_t sock_size = sizeof(struct sockaddr_in); - SOCKET acc_socket = accept(sHost, (struct sockaddr *)&user_socket, &sock_size); - defer(closesocket(acc_socket)); - char buffer[20] = {}; - const char* user_address = inet_ntop(AF_INET, &user_socket.sin_addr, buffer, 20); - if(user_address != NULL) - { - printErr("[INFO] Device %s:%d connected.\n", user_address, user_socket.sin_port); - } - CONNECTED = true; - EXIT_FLAG = false; - auto LEDThread = std::thread(threadLEDBroadcast, acc_socket, memory); - auto InputThread = std::thread(threadInputReceive, acc_socket, memory); - LEDThread.join(); - InputThread.join(); - printErr("[INFO] Exiting gracefully...\n"); - last_input_packet_id = 0; - EXIT_FLAG = true; - CONNECTED = false; - } - } - return 0; -} diff --git a/src/resources.rc b/src/resources.rc deleted file mode 100644 index 3cd792a..0000000 --- a/src/resources.rc +++ /dev/null @@ -1,36 +0,0 @@ -// -// Include the necessary resources -// -#include -#include - -#include "version.h" - -#ifdef RC_INVOKED - -// ------- version info ------------------------------------------------------- - -VS_VERSION_INFO VERSIONINFO -FILEVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0 -PRODUCTVERSION VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH,0 -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Comments", "Brokenithm-Evolved" - VALUE "FileDescription", "Brokenithm-Evolved-Android Server" - VALUE "FileVersion", VERSION - VALUE "InternalName", "Brokenithm-Evolved-Android Server" - VALUE "LegalCopyright", "(C)2021 XTindy" - VALUE "OriginalFilename", "brokenithm_server.exe" - VALUE "ProductName", "Brokenithm-Evolved" - VALUE "ProductVersion", VERSION - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0409,1200 - END -END -#endif diff --git a/src/socket.h b/src/socket.h deleted file mode 100644 index d6fa32e..0000000 --- a/src/socket.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef SOCKET_H_INCLUDED -#define SOCKET_H_INCLUDED - -#include - -#ifdef _WIN32 -#ifndef WINVER -#define WINVER 0x0501 -#endif // WINVER -#include -#include -#else -//translate windows functions to linux functions -#include -#include -#define SOCKET int -#define INVALID_SOCKET (SOCKET)(~0) -#define SOCKET_ERROR (-1) -#define closesocket close -#define SOCKADDR_IN sockaddr_in -#define ZeroMemory(d,l) memset((d), 0, (l)) -#define ioctlsocket ioctl -#ifndef SA_INTERRUPT -#define SA_INTERRUPT 0 //ignore this setting -#endif -#define SD_BOTH SHUT_RDWR -#ifndef __hpux -#include -#endif /* __hpux */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -typedef sockaddr *LPSOCKADDR; -#endif // _WIN32 - -#endif // SOCKET_H_INCLUDED diff --git a/src/struct.h b/src/struct.h deleted file mode 100644 index 0bcd407..0000000 --- a/src/struct.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef STRUCT_H_INCLUDED -#define STRUCT_H_INCLUDED - -#pragma pack(push) -#pragma pack(1) - -struct IPCMemoryInfo -{ - uint8_t airIoStatus[6]; - uint8_t sliderIoStatus[32]; - uint8_t ledRgbData[32 * 3]; - uint8_t testBtn; - uint8_t serviceBtn; - uint8_t coinInsertion; - uint8_t cardRead; - uint8_t remoteCardRead; - uint8_t remoteCardType; - uint8_t remoteCardId[10]; -}; - -struct PacketInput -{ - uint8_t packetSize; - uint8_t packetName[3]; - uint32_t packetId; - uint8_t airIoStatus[6]; - uint8_t sliderIoStatus[32]; - uint8_t testBtn; - uint8_t serviceBtn; -}; - -struct PacketInputNoAir -{ - uint8_t packetSize; - uint8_t packetName[3]; - uint32_t packetId; - uint8_t sliderIoStatus[32]; - uint8_t testBtn; - uint8_t serviceBtn; -}; - -struct PacketFunction -{ - uint8_t packetSize; - uint8_t packetName[3]; - uint8_t funcBtn; -}; - -struct PacketConnect -{ - uint8_t packetSize; - uint8_t packetName[3]; - uint8_t addrType; - uint16_t port; - union - { - struct - { - uint8_t addr[4]; - uint8_t padding[12]; - } addr4; - uint8_t addr6[16]; - } addr; -}; - -struct PacketCard -{ - uint8_t packetSize; - uint8_t packetName[3]; - uint8_t remoteCardRead; - uint8_t remoteCardType; - uint8_t remoteCardId[10]; -}; - -struct PacketPing -{ - uint8_t packetSize; - uint8_t packetName[3]; - uint64_t remotePingTime; -}; - -#pragma pack(pop) - -#endif // STRUCT_H_INCLUDED diff --git a/src/version.h b/src/version.h deleted file mode 100644 index f18a76b..0000000 --- a/src/version.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef VERSION_H_INCLUDED -#define VERSION_H_INCLUDED - -#define VERSION "V0.3.0" - -#define VERSION_MAJOR 0 -#define VERSION_MINOR 3 -#define VERSION_PATCH 0 - -#endif // VERSION_H_INCLUDED