/*++ Initialize global data. Return value: 0 = success, -1 = error. --*/ INT PAL_InitGlobals(void) { if (gpGlobals == NULL) { gpGlobals = (LPGLOBALVARS)calloc(1, sizeof(GLOBALVARS)); if (gpGlobals == NULL) { return -1; } } // // Open files // gpGlobals->f.fpFBP = UTIL_OpenRequiredFile("fbp.mkf"); gpGlobals->f.fpMGO = UTIL_OpenRequiredFile("mgo.mkf"); gpGlobals->f.fpBALL = UTIL_OpenRequiredFile("ball.mkf"); // load using csv gpGlobals->f.fpDATA = UTIL_OpenRequiredFile("data.mkf"); gpGlobals->f.fpF = UTIL_OpenRequiredFile("f.mkf"); gpGlobals->f.fpFIRE = UTIL_OpenRequiredFile("fire.mkf"); gpGlobals->f.fpRGM = UTIL_OpenRequiredFile("rgm.mkf"); // load using csv, and this will be changed to a set of files gpGlobals->f.fpSSS = UTIL_OpenRequiredFile("sss.mkf"); #ifndef PAL_WIN95 // @@@ - this is where the desc.dat get loaded. gpGlobals->lpObjectDesc = PAL_LoadObjectDesc(va("%s%s", PAL_PREFIX, "desc.dat")); #endif gpGlobals->bCurrentSaveSlot = 1; return 0; }
INT PAL_InitGlobals( VOID ) /*++ Purpose: Initialize global data. Parameters: None. Return value: 0 = success, -1 = error. --*/ { if (gpGlobals == NULL) { gpGlobals = (LPGLOBALVARS)calloc(1, sizeof(GLOBALVARS)); if (gpGlobals == NULL) { return -1; } } // // Open files // gpGlobals->f.fpFBP = UTIL_OpenRequiredFile("fbp.mkf"); gpGlobals->f.fpMGO = UTIL_OpenRequiredFile("mgo.mkf"); gpGlobals->f.fpBALL = UTIL_OpenRequiredFile("ball.mkf"); gpGlobals->f.fpDATA = UTIL_OpenRequiredFile("data.mkf"); gpGlobals->f.fpF = UTIL_OpenRequiredFile("f.mkf"); gpGlobals->f.fpFIRE = UTIL_OpenRequiredFile("fire.mkf"); gpGlobals->f.fpRGM = UTIL_OpenRequiredFile("rgm.mkf"); gpGlobals->f.fpSSS = UTIL_OpenRequiredFile("sss.mkf"); gpGlobals->f.fpVOC = UTIL_OpenRequiredFile("voc.mkf"); gpGlobals->lpObjectDesc = PAL_LoadObjectDesc(va("%s%s", PAL_PREFIX, "desc.dat")); gpGlobals->bCurrentSaveSlot = 1; return 0; }
void extract_zipfile(void) { zipfd = UTIL_OpenRequiredFile("gop.mkf.zip.tns"); if (zipfd == NULL) { printf("Can't open input file: %s\n",zipfn); return; } process_headers(); fclose(zipfd); }
filter_linear0 = %s \r\n\ "; char *readShaderFile(const char *filename, GLuint type) { FILE *fp = UTIL_OpenRequiredFile(get_glslp_path(filename)); fseek(fp,0,SEEK_END); long filesize = ftell(fp); char *buf = (char*)malloc(filesize+1); fseek(fp,0,SEEK_SET); fread(buf,filesize,1,fp); buf[filesize]='\0'; return buf; }
VOID PAL_LoadResources( VOID ) /*++ Purpose: Load the game resources if needed. Parameters: None. Return value: None. --*/ { int i, index, l, n; WORD wPlayerID, wSpriteNum; if (gpResources == NULL || gpResources->bLoadFlags == 0) { return; } // // Load scene // if (gpResources->bLoadFlags & kLoadScene) { FILE *fpMAP, *fpGOP; fpMAP = UTIL_OpenRequiredFile("map.mkf"); fpGOP = UTIL_OpenRequiredFile("gop.mkf"); if (gpGlobals->fEnteringScene) { gpGlobals->wScreenWave = 0; gpGlobals->sWaveProgression = 0; } // // Free previous loaded scene (sprites and map) // PAL_FreeEventObjectSprites(); PAL_FreeMap(gpResources->lpMap); // // Load map // i = gpGlobals->wNumScene - 1; gpResources->lpMap = PAL_LoadMap(gpGlobals->g.rgScene[i].wMapNum, fpMAP, fpGOP); if (gpResources->lpMap == NULL) { fclose(fpMAP); fclose(fpGOP); TerminateOnError("PAL_LoadResources(): Fail to load map #%d (scene #%d) !", gpGlobals->g.rgScene[i].wMapNum, gpGlobals->wNumScene); } // // Load sprites // index = gpGlobals->g.rgScene[i].wEventObjectIndex; gpResources->nEventObject = gpGlobals->g.rgScene[i + 1].wEventObjectIndex; gpResources->nEventObject -= index; if (gpResources->nEventObject > 0) { gpResources->lppEventObjectSprites = (LPSPRITE *)UTIL_calloc(gpResources->nEventObject, sizeof(LPSPRITE)); } for (i = 0; i < gpResources->nEventObject; i++, index++) { n = gpGlobals->g.lprgEventObject[index].wSpriteNum; if (n == 0) { // // this event object has no sprite // gpResources->lppEventObjectSprites[i] = NULL; continue; } l = PAL_MKFGetDecompressedSize(n, gpGlobals->f.fpMGO); gpResources->lppEventObjectSprites[i] = (LPSPRITE)UTIL_malloc(l); if (PAL_MKFDecompressChunk(gpResources->lppEventObjectSprites[i], l, n, gpGlobals->f.fpMGO) > 0) { gpGlobals->g.lprgEventObject[index].nSpriteFramesAuto = PAL_SpriteGetNumFrames(gpResources->lppEventObjectSprites[i]); } } gpGlobals->partyoffset = PAL_XY(160, 112); fclose(fpGOP); fclose(fpMAP); } // // Load player sprites // if (gpResources->bLoadFlags & kLoadPlayerSprite) { // // Free previous loaded player sprites // PAL_FreePlayerSprites(); for (i = 0; i <= (short)gpGlobals->wMaxPartyMemberIndex; i++) { wPlayerID = gpGlobals->rgParty[i].wPlayerRole; assert(wPlayerID < MAX_PLAYER_ROLES); // // Load player sprite // wSpriteNum = gpGlobals->g.PlayerRoles.rgwSpriteNum[wPlayerID]; l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO); gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l); PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum, gpGlobals->f.fpMGO); } if (gpGlobals->nFollower > 0) { // // Load the follower sprite // wSpriteNum = gpGlobals->rgParty[i].wPlayerRole; l = PAL_MKFGetDecompressedSize(wSpriteNum, gpGlobals->f.fpMGO); gpResources->rglpPlayerSprite[i] = (LPSPRITE)UTIL_malloc(l); PAL_MKFDecompressChunk(gpResources->rglpPlayerSprite[i], l, wSpriteNum, gpGlobals->f.fpMGO); } } // // Clear all of the load flags // gpResources->bLoadFlags = 0; }
INT PAL_InitText( VOID ) /*++ Purpose: Initialize the in-game texts. Parameters: None. Return value: 0 = success. -1 = memory allocation error. --*/ { FILE *fpMsg, *fpWord; int i; // // Open the message and word data files. // fpMsg = UTIL_OpenRequiredFile("m.msg"); fpWord = UTIL_OpenRequiredFile("word.dat"); // // See how many words we have // fseek(fpWord, 0, SEEK_END); i = ftell(fpWord); // // Each word has 10 bytes // g_TextLib.nWords = (i + (WORD_LENGTH - 1)) / WORD_LENGTH; // // Read the words // g_TextLib.lpWordBuf = (LPBYTE)malloc(i); if (g_TextLib.lpWordBuf == NULL) { fclose(fpWord); fclose(fpMsg); return -1; } fseek(fpWord, 0, SEEK_SET); fread(g_TextLib.lpWordBuf, i, 1, fpWord); // // Close the words file // fclose(fpWord); // // Read the message offsets. The message offsets are in SSS.MKF #3 // i = PAL_MKFGetChunkSize(3, gpGlobals->f.fpSSS) / sizeof(DWORD); g_TextLib.nMsgs = i - 1; g_TextLib.lpMsgOffset = (LPDWORD)malloc(i * sizeof(DWORD)); if (g_TextLib.lpMsgOffset == NULL) { free(g_TextLib.lpWordBuf); fclose(fpMsg); return -1; } PAL_MKFReadChunk((LPBYTE)(g_TextLib.lpMsgOffset), i * sizeof(DWORD), 3, gpGlobals->f.fpSSS); // // Read the messages. // fseek(fpMsg, 0, SEEK_END); i = ftell(fpMsg); g_TextLib.lpMsgBuf = (LPBYTE)malloc(i); if (g_TextLib.lpMsgBuf == NULL) { free(g_TextLib.lpMsgOffset); free(g_TextLib.lpWordBuf); fclose(fpMsg); return -1; } fseek(fpMsg, 0, SEEK_SET); fread(g_TextLib.lpMsgBuf, 1, i, fpMsg); fclose(fpMsg); g_TextLib.bCurrentFontColor = FONT_COLOR_DEFAULT; g_TextLib.bIcon = 0; g_TextLib.posIcon = 0; g_TextLib.nCurrentDialogLine = 0; g_TextLib.iDelayTime = 3; g_TextLib.posDialogTitle = PAL_XY(12, 8); g_TextLib.posDialogText = PAL_XY(44, 26); g_TextLib.bDialogPosition = kDialogUpper; g_TextLib.fUserSkip = FALSE; PAL_MKFReadChunk(g_TextLib.bufDialogIcons, 282, 12, gpGlobals->f.fpDATA); return 0; }
/*++ Load all the loaded sprites. --*/ VOID PAL_LoadBattleSprites(void) { int i, l, x, y, s; FILE *fp; PAL_FreeBattleSprites(); fp = UTIL_OpenRequiredFile("abc.mkf"); // // Load battle sprites for players // for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++) { s = PAL_GetPlayerBattleSprite(gpGlobals->rgParty[i].wPlayerRole); l = PAL_MKFGetDecompressedSize(s, gpGlobals->f.fpF); if (l <= 0) { continue; } g_Battle.rgPlayer[i].lpSprite = UTIL_calloc(l, 1); PAL_MKFDecompressChunk(g_Battle.rgPlayer[i].lpSprite, l, s, gpGlobals->f.fpF); // // Set the default position for this player // x = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][i][0]; y = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][i][1]; g_Battle.rgPlayer[i].posOriginal = PAL_XY(x, y); g_Battle.rgPlayer[i].pos = PAL_XY(x, y); } // // Load battle sprites for enemies // for (i = 0; i < MAX_ENEMIES_IN_TEAM; i++) { if (g_Battle.rgEnemy[i].wObjectID == 0) { continue; } l = PAL_MKFGetDecompressedSize( gpGlobals->g.rgObject[g_Battle.rgEnemy[i].wObjectID].enemy.wEnemyID, fp); if (l <= 0) { continue; } g_Battle.rgEnemy[i].lpSprite = UTIL_calloc(l, 1); PAL_MKFDecompressChunk(g_Battle.rgEnemy[i].lpSprite, l, gpGlobals->g.rgObject[g_Battle.rgEnemy[i].wObjectID].enemy.wEnemyID, fp); // // Set the default position for this enemy // x = gpGlobals->g.EnemyPos.pos[i][g_Battle.wMaxEnemyIndex].x; y = gpGlobals->g.EnemyPos.pos[i][g_Battle.wMaxEnemyIndex].y; y += g_Battle.rgEnemy[i].e.wYPosOffset; g_Battle.rgEnemy[i].posOriginal = PAL_XY(x, y); g_Battle.rgEnemy[i].pos = PAL_XY(x, y); } fclose(fp); }
INT PAL_InitFont( VOID ) /*++ Purpose: Load the font files. Parameters: None. Return value: 0 if succeed, -1 if cannot allocate memory, -2 if cannot load files. --*/ { FILE *fp; if (gpFont != NULL) { // // Already initialized // return 0; } gpFont = (LPFONT)calloc(1, sizeof(FONT)); if (gpFont == NULL) { return -1; } // // Load the wor16.asc file. // fp = UTIL_OpenRequiredFile("wor16.asc"); // // Get the size of wor16.asc file. // fseek(fp, 0, SEEK_END); gpFont->nChar = ftell(fp); gpFont->nChar /= 2; // // Read all the character codes. // gpFont->lpBufChar = (LPWORD)calloc(gpFont->nChar, sizeof(WORD)); if (gpFont->lpBufChar == NULL) { free(gpFont); gpFont = NULL; return -1; } fseek(fp, 0, SEEK_SET); fread(gpFont->lpBufChar, sizeof(WORD), gpFont->nChar, fp); // // Close wor16.asc file. // fclose(fp); // // Read all bitmaps from wor16.fon file. // fp = UTIL_OpenRequiredFile("wor16.fon"); gpFont->lpBufGlyph = (LPBYTE)calloc(gpFont->nChar, 30); if (gpFont->lpBufGlyph == NULL) { free(gpFont->lpBufChar); free(gpFont); gpFont = NULL; return -1; } // // The font glyph data begins at offset 0x682 in wor16.fon. // fseek(fp, 0x682, SEEK_SET); fread(gpFont->lpBufGlyph, 30, gpFont->nChar, fp); fclose(fp); return 0; }
VOID PAL_LoadBattleSprites( VOID ) /*++ Purpose: Load all the loaded sprites. Parameters: None. Return value: None. --*/ { int i, l, x, y, s; FILE *fp; UTIL_WriteLog(LOG_DEBUG, "[0x%08x][%s][%s] - %s", (long)PAL_LoadBattleSprites, "PAL_LoadBattleSprites", __FILE__, "start"); PAL_FreeBattleSprites(); fp = UTIL_OpenRequiredFile("abc.mkf"); // // Load battle sprites for players // for (i = 0; i <= gpGlobals->wMaxPartyMemberIndex; i++) { s = PAL_GetPlayerBattleSprite(gpGlobals->rgParty[i].wPlayerRole); l = PAL_MKFGetDecompressedSize(s, gpGlobals->f.fpF); if (l <= 0) { continue; } g_Battle.rgPlayer[i].lpSprite = UTIL_calloc(l, 1); PAL_MKFDecompressChunk(g_Battle.rgPlayer[i].lpSprite, l, s, gpGlobals->f.fpF); // // Set the default position for this player // x = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][i][0]; y = g_rgPlayerPos[gpGlobals->wMaxPartyMemberIndex][i][1]; g_Battle.rgPlayer[i].posOriginal = PAL_XY(x, y); g_Battle.rgPlayer[i].pos = PAL_XY(x, y); } // // Load battle sprites for enemies // for (i = 0; i < MAX_ENEMIES_IN_TEAM; i++) { if (g_Battle.rgEnemy[i].wObjectID == 0) { continue; } l = PAL_MKFGetDecompressedSize( gpGlobals->g.rgObject[g_Battle.rgEnemy[i].wObjectID].enemy.wEnemyID, fp); if (l <= 0) { continue; } g_Battle.rgEnemy[i].lpSprite = UTIL_calloc(l, 1); PAL_MKFDecompressChunk(g_Battle.rgEnemy[i].lpSprite, l, gpGlobals->g.rgObject[g_Battle.rgEnemy[i].wObjectID].enemy.wEnemyID, fp); // // Set the default position for this enemy // x = gpGlobals->g.EnemyPos.pos[i][g_Battle.wMaxEnemyIndex].x; y = gpGlobals->g.EnemyPos.pos[i][g_Battle.wMaxEnemyIndex].y; y += g_Battle.rgEnemy[i].e.wYPosOffset; g_Battle.rgEnemy[i].posOriginal = PAL_XY(x, y); g_Battle.rgEnemy[i].pos = PAL_XY(x, y); } fclose(fp); UTIL_WriteLog(LOG_DEBUG, "[0x%08x][%s][%s] - %s", (long)PAL_LoadBattleSprites, "PAL_LoadBattleSprites", __FILE__, "end"); }
VOID PAL_RNGPlay( INT iNumRNG, INT iStartFrame, INT iEndFrame, INT iSpeed ) /*++ Purpose: Play a RNG movie. Parameters: [IN] iNumRNG - number of the RNG movie. [IN] iStartFrame - start frame number. [IN] iEndFrame - end frame number. [IN] iSpeed - speed of playing. Return value: None. --*/ { UINT iTime; int iDelay = 800 / (iSpeed == 0 ? 16 : iSpeed); FILE *fp; fp = UTIL_OpenRequiredFile("rng.mkf"); for (; iStartFrame <= iEndFrame; iStartFrame++) { iTime = SDL_GetTicks() + iDelay; if (PAL_RNGBlitToSurface(iNumRNG, iStartFrame, gpScreen, fp) == -1) { // // Failed to get the frame, don't go further // fclose(fp); return; } // // Update the screen // VIDEO_UpdateScreen(NULL); // // Fade in the screen if needed // if (gpGlobals->fNeedToFadeIn) { PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1); gpGlobals->fNeedToFadeIn = FALSE; } // // Delay for a while // PAL_ProcessEvent(); while (SDL_GetTicks() <= iTime) { PAL_ProcessEvent(); SDL_Delay(1); } } fclose(fp); }
SDL_Color * PAL_GetPalette( INT iPaletteNum, BOOL fNight ) /*++ Purpose: Get the specified palette in pat.mkf file. Parameters: [IN] iPaletteNum - number of the palette. [IN] fNight - whether use the night palette or not. Return value: Pointer to the palette. NULL if failed. --*/ { static SDL_Color palette[256]; PAL_LARGE BYTE buf[1536]; INT i; FILE *fp; fp = UTIL_OpenRequiredFile("pat.mkf"); // // Read the palette data from the pat.mkf file // i = PAL_MKFReadChunk(buf, 1536, iPaletteNum, fp); fclose(fp); if (i < 0) { // // Read failed // return NULL; } else if (i <= 256 * 3) { // // There is no night colors in the palette // fNight = FALSE; } for (i = 0; i < 256; i++) { palette[i].r = buf[(fNight ? 256 * 3 : 0) + i * 3] << 2; palette[i].g = buf[(fNight ? 256 * 3 : 0) + i * 3 + 1] << 2; palette[i].b = buf[(fNight ? 256 * 3 : 0) + i * 3 + 2] << 2; #if 0 palette[i].r += (255 - palette[i].r) / 5; palette[i].g += (255 - palette[i].g) / 5; palette[i].b += (255 - palette[i].b) / 5; #endif } return palette; }
VOID PAL_RNGPlay( INT iNumRNG, INT iStartFrame, INT iEndFrame, INT iSpeed ) /*++ Purpose: Play a RNG movie. Parameters: [IN] iNumRNG - number of the RNG movie. [IN] iStartFrame - start frame number. [IN] iEndFrame - end frame number. [IN] iSpeed - speed of playing. Return value: None. --*/ { int iDelay = 800 / (iSpeed == 0 ? 16 : iSpeed); uint8_t *rng = (uint8_t *)malloc(65000); uint8_t *buf = (uint8_t *)malloc(65000); FILE *fp = UTIL_OpenRequiredFile("rng.mkf"); for (; rng && buf && iStartFrame <= iEndFrame; iStartFrame++) { uint32_t iTime = SDL_GetTicks() + iDelay; // // Read, decompress and render the frame // if (PAL_RNGReadFrame(buf, 65000, iNumRNG, iStartFrame, fp) < 0 || PAL_RNGBlitToSurface(rng, Decompress(buf, rng, 65000), gpScreen) == -1) { // // Failed to get the frame, don't go further // break; } // // Update the screen // VIDEO_UpdateScreen(NULL); // // Fade in the screen if needed // if (gpGlobals->fNeedToFadeIn) { PAL_FadeIn(gpGlobals->wNumPalette, gpGlobals->fNightPalette, 1); gpGlobals->fNeedToFadeIn = FALSE; } // // Delay for a while // PAL_DelayUntil(iTime); } fclose(fp); free(rng); free(buf); }