static SRes FileInStream_Read(void *pp, void *buf, size_t *size) { CFileInStream *p = (CFileInStream *)pp; return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; }
int WinX68k_LoadROMs(void) { static const char *BIOSFILE[] = { "iplrom.dat", "iplrom30.dat", "iplromco.dat", "iplromxv.dat" }; static const char FONTFILE[] = "cgrom.dat"; static const char FONTFILETMP[] = "cgrom.tmp"; FILEH fp; int i; BYTE tmp; for (fp = 0, i = 0; fp == 0 && i < NELEMENTS(BIOSFILE); ++i) { fp = File_OpenCurDir((char *)BIOSFILE[i]); } if (fp == 0) { Error("BIOS ROM not found."); return FALSE; } File_Read(fp, &IPL[0x20000], 0x20000); File_Close(fp); WinX68k_SCSICheck(); // SCSI IPL�ʤ顢$fc0000����SCSI BIOS���֤� for (i = 0; i < 0x40000; i += 2) { tmp = IPL[i]; IPL[i] = IPL[i + 1]; IPL[i + 1] = tmp; } fp = File_OpenCurDir((char *)FONTFILE); if (fp == 0) { // cgrom.tmp�����롩 fp = File_OpenCurDir((char *)FONTFILETMP); if (fp == 0) { #if 1 // �ե�������� XXX printf("�ե����ROM����������Ĥ���ޤ���\n"); return FALSE; #else MessageBox(hWndMain, "�ե����ROM����������Ĥ���ޤ���.\nWindows�ե���Ȥ��鿷���˺������ޤ�.", "����ԡ��Υ�å�����", MB_ICONWARNING | MB_OK); SSTP_SendMes(SSTPMES_MAKEFONT); make_cgromdat(FONT, FALSE, "�ͣ� �����å�", "�ͣ� ��ī"); //WinX68k_MakeFont(); //DialogBox(hInst, MAKEINTRESOURCE(IDD_PROGBAR), // hWndMain, (DLGPROC)MakeFontProc); fp = File_CreateCurDir(FONTFILETMP); if (fp) { File_Write(fp, FONT, 0xc0000); File_Close(fp); return TRUE; } return TRUE; #endif } } File_Read(fp, FONT, 0xc0000); File_Close(fp); return TRUE; }
// change the size of file int File_Truncate(Inode *myNode, off_t offset) { u_int BlockSize_byte = BLOCK_SIZE; Block_pointer *blockBuffer = NULL; Block_pointer *blockPointer; int fileBlockNumber; int firstBlockToRemove, partialBlockRewrite; int status = 0; // Check to be sure the file is bigger than offset if (offset > myNode->filesize) { printf( "Truncate beyond end of file.\n"); return -EPERM; } // Decide which block to start truncating float temp = (float) offset/ BLOCK_SIZE; firstBlockToRemove = ceil(temp); partialBlockRewrite = floor(temp); //partialBlockRewrite = firstBlockToRemove - 1; // wanna read or wirte not in the BLOCK_SIZE if(partialBlockRewrite * BLOCK_SIZE != offset){ // there is a partial block truncated, handle it int sizePartBlock = offset - partialBlockRewrite * BLOCK_SIZE; void *buffer = calloc(1, BLOCK_SIZE); status = File_Read(myNode, partialBlockRewrite * BLOCK_SIZE, sizePartBlock, buffer); if( status ){printf("read the truncating file wrong \n"); return status;} status = File_Write(myNode, partialBlockRewrite * BLOCK_SIZE, BLOCK_SIZE, buffer); if( status ) {printf("Fail to truncate the partial block \n"); return status;} } if (firstBlockToRemove * BLOCK_SIZE > myNode->filesize){ printf("No blocks to remove.\n"); }else{ // release blocks at end of file int maxFileSizeBlocks = DIRECT_BK_NUM + BLOCK_SIZE/sizeof(Block_pointer); for( fileBlockNumber = firstBlockToRemove; fileBlockNumber < maxFileSizeBlocks ; fileBlockNumber++) { if( fileBlockNumber < DIRECT_BK_NUM ) { blockPointer = &myNode->direct_bk[fileBlockNumber]; } else { if(myNode->indirect_bk.seg_no == FREE_BLOCK_NUM) break; if(blockBuffer == NULL) // if we haven't read indirect block, read them { blockBuffer = (Block_pointer *)calloc(1, BLOCK_SIZE); LogAddress LogAdd; LogAdd.seg_no = myNode->indirect_bk.seg_no; LogAdd.bk_no = myNode->indirect_bk.bk_no; status = Log_Read(&LogAdd, BLOCK_SIZE, blockBuffer); if(status) { return status; } } // change this pointer in indirect block blockPointer = &blockBuffer[fileBlockNumber - DIRECT_BK_NUM]; } if( blockPointer->seg_no == FREE_BLOCK_NUM ){ // just skip over unused blocks - there may be used ones later }else{ // decrement the seg usage table Decrement_Seg_Usage( blockPointer->seg_no, blockPointer->bk_no ); blockPointer->bk_no = FREE_BLOCK_NUM; blockPointer->seg_no = FREE_BLOCK_NUM; } } } if(blockBuffer != NULL) { if(myNode->indirect_bk.seg_no != FREE_BLOCK_NUM) Decrement_Seg_Usage(myNode->indirect_bk.seg_no, myNode->indirect_bk.bk_no); // if the indirect block is no logner needed, blank it out. if(offset < DIRECT_BK_NUM*BlockSize_byte) { myNode->indirect_bk.seg_no = FREE_BLOCK_NUM; myNode->indirect_bk.bk_no = FREE_BLOCK_NUM; }else { // push the indirect block back to the log LogAddress *tailLogAddr = tail_log_addr; status = Log_Write(myNode->ino, INDIRECT_BK_NUM, BlockSize_byte, blockBuffer, tailLogAddr); if(status) { return status; } } free(blockBuffer); } myNode->filesize = offset; return status; }
int set_modulepath(char *path, size_t len) { struct stat sb; char *homepath; #ifdef ANDROID const char *extpath; char *p, ep_buf[MAX_PATH], p6dir_buf[MAX_PATH]; FILE *fp; p6dir_buf[0] = '\0'; extpath = SDL_AndroidGetExternalStoragePath(); p6logd("extpath:%s", extpath); // get the Android external path (.ex /storage/emulated/0) strcpy(p6dir_buf, extpath); p = strstr(p6dir_buf, "/Android/data/com.fc2.blog45.hissorii/files"); if (p != NULL) { *p = '\0'; p6logd("extpath2:%s", p6dir_buf); strcat(p6dir_buf, "/px68k"); p6logd("p6dir_buf:%s", p6dir_buf); // if there is the px68k directory ... if (stat(p6dir_buf, &sb) == 0 && S_ISDIR(sb.st_mode)) { goto set_dir; } } if (extpath != NULL) { // read Android/data/com.fc2.blog45.hissorii/files/dir.txt sprintf(ep_buf, "%s/dir.txt", extpath); if ((fp = fopen(ep_buf, "r")) != NULL) { fgets(p6dir_buf, MAX_PATH - 1, fp); p6logd("p6dir:%s", p6dir_buf); fclose(fp); } } // if everything failed, try /sdcard/px68k directory if (p6dir_buf[0] == '\0') { strcpy(p6dir_buf, "/sdcard/px68k"); } set_dir: strcpy(path, p6dir_buf); p6logd("path:%s", path); sprintf(winx68k_ini, "%s/config", p6dir_buf); p6logd("config:%s", winx68k_ini); return 0; #endif #if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR == 0 puts("Iphone..."); sprintf(path, "/var/mobile/px68k"); sprintf(winx68k_ini, "/var/mobile/px68k/config"); return 0; #endif homepath = getenv("HOME"); if (homepath == 0) homepath = "."; snprintf(path, len, "%s/%s", homepath, ".keropi"); if (stat(path, &sb) < 0) { #ifdef WIN32 if (mkdir(path) < 0) { #else if (mkdir(path, 0700) < 0) { #endif perror(path); return 1; } } else { if ((sb.st_mode & S_IFDIR) == 0) { fprintf(stderr, "%s isn't directory.\n", path); return 1; } } snprintf(winx68k_ini, sizeof(winx68k_ini), "%s/%s", path, "config"); if (stat(winx68k_ini, &sb) >= 0) { if (sb.st_mode & S_IFDIR) { fprintf(stderr, "%s is directory.\n", winx68k_ini); return 1; } } return 0; } void LoadConfig(void) { int i, j; char buf[CFGLEN]; FILEH fp; winx = GetPrivateProfileInt(ini_title, "WinPosX", 0, winx68k_ini); winy = GetPrivateProfileInt(ini_title, "WinPosY", 0, winx68k_ini); #ifdef PSP Config.FrameRate = (BYTE)GetPrivateProfileInt(ini_title, "FrameRate", 5, winx68k_ini); #else Config.FrameRate = (BYTE)GetPrivateProfileInt(ini_title, "FrameRate", 7, winx68k_ini); #endif if (!Config.FrameRate) Config.FrameRate = 7; GetPrivateProfileString(ini_title, "StartDir", "", buf, MAX_PATH, winx68k_ini); if (buf[0] != 0) strncpy(filepath, buf, sizeof(filepath)); else filepath[0] = 0; Config.OPM_VOL = GetPrivateProfileInt(ini_title, "OPM_Volume", 12, winx68k_ini); Config.PCM_VOL = GetPrivateProfileInt(ini_title, "PCM_Volume", 15, winx68k_ini); Config.MCR_VOL = GetPrivateProfileInt(ini_title, "MCR_Volume", 13, winx68k_ini); #ifdef PSP Config.SampleRate = GetPrivateProfileInt(ini_title, "SampleRate", 11025, winx68k_ini); #else Config.SampleRate = GetPrivateProfileInt(ini_title, "SampleRate", 22050, winx68k_ini); #endif Config.BufferSize = GetPrivateProfileInt(ini_title, "BufferSize", 50, winx68k_ini); Config.MouseSpeed = GetPrivateProfileInt(ini_title, "MouseSpeed", 10, winx68k_ini); GetPrivateProfileString(ini_title, "FDDStatWin", "1", buf, CFGLEN, winx68k_ini); Config.WindowFDDStat = solveBOOL(buf); GetPrivateProfileString(ini_title, "FDDStatFullScr", "1", buf, CFGLEN, winx68k_ini); Config.FullScrFDDStat = solveBOOL(buf); GetPrivateProfileString(ini_title, "DSAlert", "1", buf, CFGLEN, winx68k_ini); Config.DSAlert = solveBOOL(buf); GetPrivateProfileString(ini_title, "SoundLPF", "1", buf, CFGLEN, winx68k_ini); Config.Sound_LPF = solveBOOL(buf); GetPrivateProfileString(ini_title, "UseRomeo", "0", buf, CFGLEN, winx68k_ini); Config.SoundROMEO = solveBOOL(buf); GetPrivateProfileString(ini_title, "MIDI_SW", "1", buf, CFGLEN, winx68k_ini); Config.MIDI_SW = solveBOOL(buf); GetPrivateProfileString(ini_title, "MIDI_Reset", "0", buf, CFGLEN, winx68k_ini); Config.MIDI_Reset = solveBOOL(buf); Config.MIDI_Type = GetPrivateProfileInt(ini_title, "MIDI_Type", 1, winx68k_ini); GetPrivateProfileString(ini_title, "JoySwap", "0", buf, CFGLEN, winx68k_ini); Config.JoySwap = solveBOOL(buf); GetPrivateProfileString(ini_title, "JoyKey", "0", buf, CFGLEN, winx68k_ini); Config.JoyKey = solveBOOL(buf); GetPrivateProfileString(ini_title, "JoyKeyReverse", "0", buf, CFGLEN, winx68k_ini); Config.JoyKeyReverse = solveBOOL(buf); GetPrivateProfileString(ini_title, "JoyKeyJoy2", "0", buf, CFGLEN, winx68k_ini); Config.JoyKeyJoy2 = solveBOOL(buf); GetPrivateProfileString(ini_title, "SRAMBootWarning", "1", buf, CFGLEN, winx68k_ini); Config.SRAMWarning = solveBOOL(buf); GetPrivateProfileString(ini_title, "WinDrvLFN", "1", buf, CFGLEN, winx68k_ini); Config.LongFileName = solveBOOL(buf); GetPrivateProfileString(ini_title, "WinDrvFDD", "1", buf, CFGLEN, winx68k_ini); Config.WinDrvFD = solveBOOL(buf); Config.WinStrech = GetPrivateProfileInt(ini_title, "WinStretch", 1, winx68k_ini); GetPrivateProfileString(ini_title, "DSMixing", "0", buf, CFGLEN, winx68k_ini); Config.DSMixing = solveBOOL(buf); Config.XVIMode = (BYTE)GetPrivateProfileInt(ini_title, "XVIMode", 0, winx68k_ini); GetPrivateProfileString(ini_title, "CDROM_ASPI", "1", buf, CFGLEN, winx68k_ini); Config.CDROM_ASPI = solveBOOL(buf); Config.CDROM_SCSIID = (BYTE)GetPrivateProfileInt(ini_title, "CDROM_SCSIID", 6, winx68k_ini); Config.CDROM_ASPI_Drive = (BYTE)GetPrivateProfileInt(ini_title, "CDROM_ASPIDrv", 0, winx68k_ini); Config.CDROM_IOCTRL_Drive = (BYTE)GetPrivateProfileInt(ini_title, "CDROM_CTRLDrv", 16, winx68k_ini); GetPrivateProfileString(ini_title, "CDROM_Enable", "1", buf, CFGLEN, winx68k_ini); Config.CDROM_Enable = solveBOOL(buf); GetPrivateProfileString(ini_title, "SSTP_Enable", "0", buf, CFGLEN, winx68k_ini); Config.SSTP_Enable = solveBOOL(buf); Config.SSTP_Port = GetPrivateProfileInt(ini_title, "SSTP_Port", 11000, winx68k_ini); GetPrivateProfileString(ini_title, "ToneMapping", "0", buf, CFGLEN, winx68k_ini); Config.ToneMap = solveBOOL(buf); GetPrivateProfileString(ini_title, "ToneMapFile", "", buf, MAX_PATH, winx68k_ini); if (buf[0] != 0) strcpy(Config.ToneMapFile, buf); else Config.ToneMapFile[0] = 0; Config.MIDIDelay = GetPrivateProfileInt(ini_title, "MIDIDelay", Config.BufferSize*5, winx68k_ini); Config.MIDIAutoDelay = GetPrivateProfileInt(ini_title, "MIDIAutoDelay", 1, winx68k_ini); Config.VkeyScale = GetPrivateProfileInt(ini_title, "VkeyScale", 4, winx68k_ini); Config.VbtnSwap = GetPrivateProfileInt(ini_title, "VbtnSwap", 0, winx68k_ini); Config.JoyOrMouse = GetPrivateProfileInt(ini_title, "JoyOrMouse", 0, winx68k_ini); Config.HwJoyAxis[0] = GetPrivateProfileInt(ini_title, "HwJoyAxis0", 0, winx68k_ini); Config.HwJoyAxis[1] = GetPrivateProfileInt(ini_title, "HwJoyAxis1", 1, winx68k_ini); Config.HwJoyHat = GetPrivateProfileInt(ini_title, "HwJoyHat", 0, winx68k_ini); for (i = 0; i < 8; i++) { sprintf(buf, "HwJoyBtn%d", i); Config.HwJoyBtn[i] = GetPrivateProfileInt(ini_title, buf, i, winx68k_ini); } Config.NoWaitMode = GetPrivateProfileInt(ini_title, "NoWaitMode", 0, winx68k_ini); for (i=0; i<2; i++) { for (j=0; j<8; j++) { sprintf(buf, "Joy%dButton%d", i+1, j+1); Config.JOY_BTN[i][j] = GetPrivateProfileInt(ini_title, buf, j, winx68k_ini); } } for (i = 0; i < 2; i++) { sprintf(buf, "FDD%d", i); GetPrivateProfileString(ini_title, buf, "", Config.FDDImage[i], MAX_PATH, winx68k_ini); } for (i=0; i<16; i++) { sprintf(buf, "HDD%d", i); GetPrivateProfileString(ini_title, buf, "", Config.HDImage[i], MAX_PATH, winx68k_ini); } #if 0 fp = File_OpenCurDir(KEYCONFFILE); if (fp) { File_Read(fp, KeyTable, 512); File_Close(fp); } #endif }
/******************************************************************************* Func Name: AES_Driver_Decrypt Date Created: 2014-3-13 Author: Zhulinfeng Description: Decrypt file. Input: NONE Output: NONE Return: int AES_DRIVER_SUCCESS AES_DRIVER_ERR AES_DRIVER_SYSERR //system error, exit program Caution: Called by AES_Driver_Fsm ---------------------------------------------------------------------------- Modification History Date Author Modification ---------------------------------------------------------------------------- YYYY-MM-DD *******************************************************************************/ PRIVATE int AES_Driver_Decrypt() { int iret = AES_DRIVER_SUCCESS; struct AES_Key_S smyKey; struct File_S smyFile; /**Get out file path**/ int ipathCount = 0; int ifileNameIndex = 0; while( '\0' != cpathBuf[ifileNameIndex]) { ifileNameIndex++; } while('/' != cpathBuf[ifileNameIndex] && ifileNameIndex > 0) { ifileNameIndex--; } char coutFile[AES_DRIVER_PATHLENGTH + 1]; for(ipathCount; ipathCount < AES_DRIVER_PATHLENGTH + 1; ipathCount++) { if(ipathCount <= ifileNameIndex) { coutFile[ipathCount] = cpathBuf[ipathCount]; } else if(1 == ipathCount - ifileNameIndex) { coutFile[ipathCount] = '_'; } else { coutFile[ipathCount] = cpathBuf[ipathCount - 1]; } if('\0' == coutFile[ipathCount]) { break; } } /**open in file and out file**/ printf("Opening files...\n"); File_Init(&smyFile); if(DS_SUCCESS != File_OpenInFile(cpathBuf, &smyFile) ) { iret = AES_DRIVER_ERR; if(DS_SUCCESS != File_Finit(&smyFile)) { iret = AES_DRIVER_SYSERR; } printf("Invalid file path!\n"); return iret; } if(DS_SUCCESS != File_OpenOutFile(coutFile, &smyFile)) { iret = AES_DRIVER_ERR; if(DS_SUCCESS != File_Finit(&smyFile)) { iret = AES_DRIVER_SYSERR; } printf("Invalid file path!\n"); return iret; } printf("Opening files done.\n"); /**make key**/ printf("Making subkeys...\n"); byte bkey[AES_KEY_SIZE]; int ikeyCount = 0; for(ikeyCount; ikeyCount < AES_KEY_SIZE; ikeyCount++) { byte btmp = 0; btmp |= DS_16to2(ckeyBuf[ikeyCount * 2]); btmp <<= 4; btmp |= DS_16to2(ckeyBuf[ikeyCount * 2 + 1]); bkey[ikeyCount] = btmp; } AES_Key_Set(&smyKey, bkey, AES_KEY_SIZE); AES_Key_Make(&smyKey); printf("Making subkeys done.\n"); /**ecnrypting**/ printf("Decrypting...\n"); while(1) { int ifileFlag = File_Read(&smyFile); int ibufIndex = 0; while(ibufIndex < smyFile.uibyteCount) { AES_Iter_Decrypt(smyFile.DATABUF + ibufIndex, AES_PAGE_SIZE, &smyKey); ibufIndex += AES_PAGE_SIZE; } if(DS_SUCCESS != ifileFlag) { smyFile.uibyteCount -= AES_PAGE_SIZE; smyFile.uibyteCount -= (unsigned int)smyFile.DATABUF[smyFile.uibyteCount - 1]; } File_Write(&smyFile); /**end encrypting**/ if(DS_SUCCESS != ifileFlag) { break; } } printf("Decrypting done.\n"); /**set off resources**/ if(DS_SUCCESS != File_Finit(&smyFile)) { iret = AES_DRIVER_SYSERR; } return iret; }
def(size_t, Read, WrBuffer buf) { return File_Read(this, buf.ptr, buf.size); }
bool File::Read(void* dst, int size) { return file ? File_Read(file, dst, size) : false; }
static void GUI_Mentat_ShowHelp(void) { struct { uint8 notused[8]; uint32 length; } info; uint8 *subject; uint16 i; bool noDesc; uint8 fileID; uint32 offset; char *compressedText; char *desc; char *picture; char *text; bool loc12; subject = s_helpSubjects; for (i = 0; i < s_selectedHelpSubject; i++) subject = String_NextString(subject); noDesc = (subject[5] == '0'); offset = HTOBE32(*(uint32 *)(subject + 1)); fileID = ChunkFile_Open(s_mentatFilename); ChunkFile_Read(fileID, HTOBE32(CC_INFO), &info, 12); ChunkFile_Close(fileID); info.length = HTOBE32(info.length); text = g_readBuffer; compressedText = GFX_Screen_Get_ByIndex(SCREEN_1); fileID = File_Open(s_mentatFilename, FILE_MODE_READ); File_Seek(fileID, offset, 0); File_Read(fileID, compressedText, info.length); String_Decompress(compressedText, text); String_TranslateSpecial(text, text); File_Close(fileID); while (*text != '*' && *text != '?') text++; loc12 = (*text == '*'); *text++ = '\0'; if (noDesc) { uint16 index; picture = g_scenario.pictureBriefing; desc = NULL; text = (char *)g_readBuffer; index = *text - 44 + g_campaignID * 4 + STR_HOUSE_HARKONNENFROM_THE_DARK_WORLD_OF_GIEDI_PRIME_THE_SAVAGE_HOUSE_HARKONNEN_HAS_SPREAD_ACROSS_THE_UNIVERSE_A_CRUEL_PEOPLE_THE_HARKONNEN_ARE_RUTHLESS_TOWARDS_BOTH_FRIEND_AND_FOE_IN_THEIR_FANATICAL_PURSUIT_OF_POWER + g_playerHouseID * 40; strncpy(g_readBuffer, String_Get_ByIndex(index), g_readBufferSize); } else { picture = (char *)g_readBuffer; desc = text; while (*text != '\0' && *text != 0xC) text++; if (*text != '\0') *text++ = '\0'; } GUI_Mentat_Loop(picture, desc, text, loc12 ? 1 : 0, g_widgetMentatFirst); GUI_Widget_MakeNormal(g_widgetMentatFirst, false); GUI_Mentat_LoadHelpSubjects(false); GUI_Mentat_Create_HelpScreen_Widgets(); GUI_Mentat_Draw(true); }
void TestPerformance() { // puzzle board char puzzle_board_data[] = { 't', 'h', 'i', 's', 'w', 'a', 't', 's', 'o', 'a', 'h', 'g', 'f', 'g', 'd', 't' }; PuzzleBoard puzzle_board = { puzzle_board_data, 4, 4 }; // dictionary char* buf; long num; if (!File_Read("res/wordsEn/wordsEn.txt", &buf, &num)) { MASSERT_MSG(0, "File (res/wordsEn/wordsEn.txt) not exist!\n"); MLOG("File (res/wordsEn/wordsEn.txt) not exist!\n"); return; } if (num == 0) { MLOG("dictionary is empty\n"); return; } Array dictionary; ArrayInit(&dictionary, 8, sizeof(char*)); char* p = buf; char* q = p; while (p) { if (*p == '\r' || *p == '\n') { *p = '\0'; if (q != p) { ArrayPush(&dictionary, &q); } ++p; q = p; continue; } if (*p == '\0') { if (q != p) { ArrayPush(&dictionary, &q); } break; } ++p; } // performance test PerformanceTest test; size_t piece_size = dictionary.used / 128; for (int i = 1; i <= 32; ++i) { size_t num = i * piece_size; size_t count; Array ret; Array cur_dictionary; ArrayInit(&cur_dictionary, 8, sizeof(char*)); for (size_t j = 0; j < num; ++j) { ArrayPush(&cur_dictionary, ArrayGet(&dictionary, j)); } // solution 1 PERFORMANCE_TEST_ADD(test, "puzzle - solution 1", (int)num, ret = solution1_Function(&puzzle_board, &cur_dictionary)); count = ArrayUsed(&ret); MLOG("solution 1:\n"); for (size_t index = 0; index < count; ++index) { RetWord* word = (RetWord*)ArrayGet(&ret, index); MLOG("%s (%d, %d) - (%d, %d)\n", word->word, word->start_x, word->start_y, word->end_x, word->end_y); } ArrayDestroy(&ret); // solution 2 PERFORMANCE_TEST_ADD(test, "puzzle - solution 2", (int)num, ret = solution2_Function(&puzzle_board, &cur_dictionary)); count = ArrayUsed(&ret); MLOG("solution 1:\n"); for (size_t index = 0; index < count; ++index) { RetWord* word = (RetWord*)ArrayGet(&ret, index); MLOG("%s (%d, %d) - (%d, %d)\n", word->word, word->start_x, word->start_y, word->end_x, word->end_y); } ArrayDestroy(&ret); ArrayDestroy(&cur_dictionary); } test.WriteCompareToFile("puzzle.txt"); // destroy ArrayDestroy(&dictionary); free(buf); }
void Mouse_SetMouseMode(uint8 mouseMode, const char *filename) { switch (mouseMode) { default: break; case INPUT_MOUSE_MODE_NORMAL: g_mouseMode = mouseMode; if (g_mouseFileID != 0xFF) { Input_Flags_ClearBits(INPUT_FLAG_KEY_RELEASE); File_Close(g_mouseFileID); } g_mouseFileID = 0xFF; g_var_701B = true; break; case INPUT_MOUSE_MODE_RECORD: if (g_mouseFileID != 0xFF) break; File_Delete(filename); File_Create(filename); Tools_RandomLCG_Seed(0x21433412); g_mouseFileID = File_Open(filename, 3); g_mouseMode = mouseMode; Input_Flags_SetBits(INPUT_FLAG_KEY_RELEASE); Input_HandleInput(0x2D); break; case INPUT_MOUSE_MODE_PLAY: if (g_mouseFileID == 0xFF) { g_mouseFileID = File_Open(filename, 1); Tools_RandomLCG_Seed(0x21433412); } g_var_701B = true; File_Read(g_mouseFileID, &g_var_7013, 2); if (File_Read(g_mouseFileID, &g_var_7015, 2) != 2) break;; if ((g_var_7013 >= 0x41 && g_var_7013 <= 0x44) || g_var_7013 == 0x2D) { File_Read(g_mouseFileID, &g_var_7017, 2); if (File_Read(g_mouseFileID, &g_var_7019, 2) == 2) { g_mouseX = g_var_7017; g_mouseY = g_var_7019; g_prevButtonState = 0; GUI_Mouse_Hide_Safe(); GUI_Mouse_Show_Safe(); g_var_701B = false; break; } g_var_701B = true; break; } g_var_701B = false; break; } g_timerInput = 0; g_mouseMode = mouseMode; }
struct map *Model_MapLoad(struct server *server, char *filename) { int size; struct map *map; char buffer[1024]; char *file; int i; map = calloc(1, sizeof(*map)); if (!map) { return NULL; } if (server->data_dir) { snprintf(buffer, sizeof(buffer), "%s/%s", server->data_dir, filename); file = buffer; } else { file = filename; } file = File_Read(file, &size); if (file == NULL) { return NULL; } map->data = (unsigned char *)file; map->header = (struct model_header *)file; map->mod_base = (unsigned char *)map->header; map->version = LittleLong(map->header->version); printf("%s - version: %i\n", filename, map->version); for (i=0;i<sizeof(struct model_header)/4;i++) ((int *)map->header)[i] = LittleLong(((int *)map->header)[i]); for (i=0; i<HEADER_LUMPS; i++) { if (i == LUMP_ENTITIES) continue; map->checksum ^= LittleLong(MD4_BlockChecksum((void *)map->mod_base + map->header->lumps[i].fileofs, map->header->lumps[i].filelen)); if (i == LUMP_VISIBILITY || i == LUMP_LEAFS || i == LUMP_NODES) continue; map->checksum2 ^= LittleLong(MD4_BlockChecksum((void *)map->mod_base + map->header->lumps[i].fileofs, map->header->lumps[i].filelen)); } memset(map->novis, 0xff, sizeof(map->novis)); map->planes = Model_LoadPlanes(&map->header->lumps[LUMP_PLANES], map->mod_base, &map->planes_count); if (map->planes) { map->entity_string = strdup((char *)map->mod_base + map->header->lumps[LUMP_ENTITIES].fileofs); if (map->entity_string) { map->leafs = Model_LoadLeafs(&map->header->lumps[LUMP_LEAFS], map->mod_base, &map->leafs_count); if (map->leafs) { map->nodes = Model_LoadNodes(&map->header->lumps[LUMP_NODES], map->mod_base, &map->nodes_count, map->planes, map->leafs); if (map->nodes) { map->clipnodes = Model_LoadClipnodes(&map->header->lumps[LUMP_CLIPNODES], map->mod_base, &map->clipnodes_count); if (map->clipnodes) { if (Model_MapLoadSubmodels(map)) { if (Model_MapCreateHulls(map)) { if (Model_MapCreatePVS(map)) { if (Model_MapCreatePHS(map)) { free(map->data); map->data = NULL; return map; } else printf("Model_MapCreatePHS failed.\n"); } else printf("Model_MapCreatePVS failed.\n"); } } else printf("Model_LoadSubmodels failed. %i\n", map->submodels_count); } else printf("Model_LoadClipnodes failed.\n"); } } } } Model_MapCleanup(map); return NULL; }
static void CoreOS_Pack(const char *outfile, const char **filelist, u32 files) { struct coreHdr *hdr = NULL; struct coreEntry *entry = NULL; FILE *fp; u32 i, j; /* Create file */ fp = fopen(outfile, "wb"); if (!fp) { fprintf(stderr, "ERROR: Could not create file \"%s\"! (%d)\n", outfile, errno); return; } /* Allocate memory */ hdr = malloc(sizeof(*hdr)); entry = malloc(sizeof(*entry) * files); /* Write empty header */ fwrite(hdr, 1, sizeof(*hdr), fp); /* Write empty entries */ fwrite(entry, 1, sizeof(*entry) * files, fp); /* Pack entries */ for (i = 0; i < files; ++i) { const char *filename = filelist[i]; u64 offset = ftell(fp); u8 *buffer = NULL; u32 buflen; /* Read file */ buflen = File_Read(filename, &buffer); if (buflen <= 0) { fprintf(stderr, "ERROR: Could not pack file \"%s\"! (%d)\n", filename, buflen); goto out; } /* File info */ printf("File: %-32s (offset: 0x%08llX, size: %.2f MB)\n", filename, offset, buflen / MEGABYTE); /* Write entry */ fwrite(buffer, 1, buflen, fp); /* Write padding */ for (j = 0; j < (buflen % 4); ++j) fputc(0, fp); /* Free buffer */ free(buffer); /* Fill entry */ entry[i].offset = Swap64(offset); entry[i].filesize = Swap64(buflen); strncpy(entry[i].filename, filename, FILENAME_LEN); } /* Fill header */ hdr->unk = Swap32(1); hdr->files = Swap32(files); hdr->size = Swap64(ftell(fp)); /* Write header */ fseek(fp, 0, SEEK_SET); fwrite(hdr, 1, sizeof(*hdr), fp); /* Write entries */ fwrite(entry, 1, sizeof(*entry) * files, fp); out: /* Close file */ if (fp) fclose(fp); /* Free buffers */ if (hdr) free(hdr); if (entry) free(entry); }
int main(int argc, const char **argv) { char mode; /* Check arguments */ if (argc < 3) { fprintf(stderr, "Pack CoreOS : %s p <output pkg> <files...>\n", argv[0]); fprintf(stderr, "Unpack CoreOS: %s u <decrypted CORE_OS_PACKAGE.pkg>\n", argv[0]); return 0; } /* Read arguments */ mode = argv[1][0]; /* Check mode */ switch (mode) { case 'p': case 'P': { const char **filelist = argv + 3; const char *filename = argv[2]; u32 files = (argc - 3); /* No files */ if (!files) { fprintf(stderr, "ERROR: No files have been specified!\n"); break; } /* Pack CoreOS */ CoreOS_Pack(filename, filelist, files); break; } case 'u': case 'U': { const char *filename; u8 *buffer = NULL; u32 buflen; /* Read arguments */ filename = argv[2]; /* Read file */ buflen = File_Read(filename, &buffer); if (buflen <= 0) { fprintf(stderr, "ERROR: Could not read file \"%s\"! (%d)\n", filename, buflen); break; } /* Unpack CoreOS */ CoreOS_Unpack(buffer); /* Free buffer */ free(buffer); break; } default: fprintf(stderr, "ERROR: Invalid mode specified! (%c)\n", mode); } return 0; }