DECL(int, FSOpenFile, void *pClient, void *pCmd, const char *path, const char *mode, int *handle, int error) { int my_ret = -1; error = 0xffffffff; if ((int)bss_ptr != 0x0a000000) { int client = client_num(pClient); if (client < MAX_CLIENT && client >= 0) { int ret; my_ret = cafiine_fopen(bss.socket_fsa[client], &ret, path, mode, handle); if (my_ret == 0) { // File exists in cafiine server, a new handle has been created return ret; } else if (my_ret >= 1) { // File has been requested from cafiine server, ret = real_FSOpenFile(pClient, pCmd, path, mode, handle, error); if (ret >= 0) { int size = (my_ret == 1 ? DUMP_BLOCK_SIZE : DUMP_BLOCK_SIZE_SLOW); cafiine_send_handle(bss.socket_fsa[client], client, path, *handle); void* buffer = memalign(sizeof(char) * size, 0x40); int ret2; while ((ret2 = real_FSReadFile(pClient, pCmd, buffer, 1, size, *handle, 0, error)) > 0) cafiine_send_file(bss.socket_fsa[client], buffer, ret2, *handle); cafiine_fclose(bss.socket_fsa[client], &ret2, *handle); real_FSSetPosFile(pClient, pCmd, *handle, 0, error); } return ret; } } } return real_FSOpenFile(pClient, pCmd, path, mode, handle, error); }
DECL(int, FSCloseFile, void *pClient, void *pCmd, int fd, int error) { if ((int)bss_ptr != 0x0a000000 && ((fd & MASK_FD) == MASK_FD)) { int client = client_num(pClient); if (client < MAX_CLIENT && client >= 0) { int ret; if (cafiine_fclose(bss.socket_fsa[client], &ret, fd) == 0) { return ret; } } } return real_FSCloseFile(pClient, pCmd, fd, error); }