int CModel::Read (char *filename, short nModel, int bFlipV, int bCustom) { if (m_nModel >= 0) return 0; CFile cf; char fileId [4]; int i, nLength, nFrames, nSubModels, bTimed = 0; bLogOOF = (fErr != NULL) && FindArg ("-printoof"); nIndent = 0; OOF_PrintLog ("\nreading %s/%s\n", gameFolders.szModelDir [bCustom], filename); if (!(*filename && cf.Open (filename, gameFolders.szModelDir [bCustom], "rb", 0))) { OOF_PrintLog (" file not found"); return 0; } if (!cf.Read (fileId, sizeof (fileId), 1)) { OOF_PrintLog (" invalid file id\n"); cf.Close (); return 0; } if (strncmp (fileId, "PSPO", 4)) { OOF_PrintLog (" invalid file id\n"); cf.Close (); return 0; } Init (); m_nModel = nModel; m_bCustom = bCustom; m_nVersion = OOF_ReadInt (cf, "nVersion"); if (m_nVersion >= 2100) m_nFlags |= OOF_PMF_LIGHTMAP_RES; if (m_nVersion >= 22) { bTimed = 1; m_nFlags |= OOF_PMF_TIMED; m_frameInfo.m_nFirstFrame = 0; m_frameInfo.m_nLastFrame = 0; } nSubModels = 0; while (!cf.EoF ()) { char chunkID [4]; if (!cf.Read (chunkID, sizeof (chunkID), 1)) { cf.Close (); return 0; } OOF_PrintLog (" chunkID = '%c%c%c%c'\n", chunkID [0], chunkID [1], chunkID [2], chunkID [3]); nLength = OOF_ReadInt (cf, "nLength"); switch (ListType (chunkID)) { case 0: if (!ReadTextures (cf)) { Destroy (); return 0; } break; case 1: if (!ReadInfo (cf)) { Destroy (); return 0; } break; case 2: if (!m_subModels [nSubModels].Read (cf, this, bFlipV)) { Destroy (); return 0; } nSubModels++; break; case 3: if (!m_gunPoints.Read (cf, m_nVersion >= 1908, MAX_GUNS)) { Destroy (); return 0; } break; case 4: if (!m_specialPoints.Read (cf)) { Destroy (); return 0; } break; case 5: if (!m_attachPoints.Read (cf)) { Destroy (); return 0; } break; case 6: nFrames = m_frameInfo.m_nFrames; if (!bTimed) m_frameInfo.m_nFrames = OOF_ReadInt (cf, "nFrames"); for (i = 0; i < m_nSubModels; i++) if (!m_subModels [i].m_posAnim.Read (cf, this, bTimed)) { Destroy (); return 0; } if (m_frameInfo.m_nFrames < nFrames) m_frameInfo.m_nFrames = nFrames; break; case 7: case 8: nFrames = m_frameInfo.m_nFrames; if (!bTimed) m_frameInfo.m_nFrames = OOF_ReadInt (cf, "nFrames"); for (i = 0; i < m_nSubModels; i++) if (!m_subModels [i].m_rotAnim.Read (cf, this, bTimed)) { Destroy (); return 0; } if (m_frameInfo.m_nFrames < nFrames) m_frameInfo.m_nFrames = nFrames; break; case 9: if (!m_armament.Read (cf)) { Destroy (); return 0; } break; case 10: if (!m_attachPoints.ReadNormals (cf)) { Destroy (); return 0; } break; default: cf.Seek (nLength, SEEK_CUR); break; } } cf.Close (); ConfigureSubModels (); BuildAnimMatrices (); AssignChildren (); LinkBatteries (); BuildPosTickRemapList (); BuildRotTickRemapList (); gameData.models.bHaveHiresModel [this - gameData.models.oofModels [bCustom != 0].Buffer ()] = 1; return 1; }
int ReadConfigFile (void) { CFile cf; char line [80], *token, *value, *ptr; ubyte gamma; tJoyAxisCal cal [7]; int i; strcpy (gameConfig.szLastPlayer, ""); memset (cal, 0, sizeof (cal)); JoySetCalVals (cal, sizeofa (cal)); gameConfig.nDigiVolume = 8; gameConfig.nMidiVolume = 8; gameConfig.nRedbookVolume = 8; gameConfig.nControlType = 0; gameConfig.bReverseChannels = 0; //set these here in case no cfg file bHiresMoviesSave = gameOpts->movies.bHires; bRedbookEnabledSave = redbook.Enabled (); if (!cf.Open ("descent.cfg", gameFolders.szConfigDir, "rt", 0)) return 1; while (!cf.EoF ()) { memset (line, 0, 80); cf.GetS (line, 80); ptr = line; while (::isspace (*ptr)) ptr++; if (*ptr != '\0') { token = strtok (ptr, "="); value = strtok (NULL, "="); if (!(value && token)) { PrintLog ("configuration file (descent.cfg) looks messed up.\n"); continue; } if (value [strlen (value) - 1] == '\n') value [strlen (value) - 1] = 0; if (!strcmp (token, pszDigiVolume)) gameConfig.nDigiVolume = (ubyte) strtol (value, NULL, 10); else if (!strcmp (token, pszMidiVolume)) gameConfig.nMidiVolume = (ubyte) strtol (value, NULL, 10); else if (!strcmp (token, pszRedbookEnabled)) redbook.Enable (bRedbookEnabledSave = strtol (value, NULL, 10)); else if (!strcmp (token, pszRedbookVolume)) gameConfig.nRedbookVolume = (ubyte) strtol (value, NULL, 10); else if (!strcmp (token, pszStereoRev)) gameConfig.bReverseChannels = (ubyte) strtol (value, NULL, 10); else if (!strcmp (token, pszGammaLevel)) { gamma = (ubyte) strtol (value, NULL, 10); paletteManager.SetGamma (gamma); } else if (!strcmp (token, pszDetailLevel)) { gameStates.app.nDetailLevel = strtol (value, NULL, 10); if (gameStates.app.nDetailLevel == NUM_DETAIL_LEVELS-1) { int count,dummy,oc,od,wd,wrd,da,sc; count = sscanf (value, "%d,%d,%d,%d,%d,%d,%d\n", &dummy, &oc, &od, &wd, &wrd, &da, &sc); if (count == 7) { gameStates.render.detail.nObjectComplexity = oc; gameStates.render.detail.nObjectDetail = od; gameStates.render.detail.nWallDetail = wd; gameStates.render.detail.nWallRenderDepth = wrd; gameStates.render.detail.nDebrisAmount = da; gameStates.sound.nSoundChannels = sc; InitCustomDetails (); } } } else if (!strcmp (token, pszJoystickMin)) sscanf (value, "%d,%d,%d,%d", &cal [0].nMin, &cal [1].nMin, &cal [2].nMin, &cal [3].nMin); else if (!strcmp (token, pszJoystickMax)) sscanf (value, "%d,%d,%d,%d", &cal [0].nMax, &cal [1].nMax, &cal [2].nMax, &cal [3].nMax); else if (!strcmp (token, pszJoystickCen)) sscanf (value, "%d,%d,%d,%d", &cal [0].nCenter, &cal [1].nCenter, &cal [2].nCenter, &cal [3].nCenter); else if (!strcmp (token, pszLastPlayer)) { char * p; strncpy (gameConfig.szLastPlayer, value, CALLSIGN_LEN); p = strchr (gameConfig.szLastPlayer, '\n'); if (p) *p = 0; } else if (!strcmp (token, pszLastMission)) { int j = MsnHasGameVer (value) ? 4 : 0; strncpy (gameConfig.szLastMission, value + j, MISSION_NAME_LEN); char *p = strchr (gameConfig.szLastMission, '\n'); if (p) *p = 0; } else if (!strcmp (token, pszVrType)) gameConfig.vrType = strtol (value, NULL, 10); else if (!strcmp (token, pszVrResolution)) gameConfig.vrResolution = strtol (value, NULL, 10); else if (!strcmp (token, pszVrTracking)) gameConfig.vrTracking = strtol (value, NULL, 10); else if (!strcmp (token, pszD2XVersion)) gameConfig.nVersion = strtoul (value, NULL, 10); else if (!strcmp (token, pszHiresMovies) && gameStates.app.bNostalgia) bHiresMoviesSave = gameOpts->movies.bHires = strtol (value, NULL, 10); } } cf.Close (); i = FindArg ("-volume"); if (i > 0) { i = atoi (pszArgList [i + 1]); if (i < 0) i = 0; else if (i > 100) i = 100; gameConfig.nDigiVolume = gameConfig.nMidiVolume = gameConfig.nRedbookVolume = (i * 8) / 100; } if (gameConfig.nDigiVolume > 8) gameConfig.nDigiVolume = 8; if (gameConfig.nMidiVolume > 8) gameConfig.nMidiVolume = 8; if (gameConfig.nRedbookVolume > 8) gameConfig.nRedbookVolume = 8; audio.SetVolumes ((gameConfig.nDigiVolume * 32768) / 8, (gameConfig.nMidiVolume * 128) / 8); if (cf.Open ("descentw.cfg", gameFolders.szConfigDir, "rt", 0)) { while (!cf.EoF ()) { memset (line, 0, 80); cf.GetS (line, 80); ptr = line; while (::isspace(*ptr)) ptr++; if (*ptr != '\0') { token = strtok(ptr, "="); value = strtok(NULL, "="); if (!(value && token)) { PrintLog ("configuration file (descentw.cfg) looks messed up.\n"); continue; } if (value [strlen(value)-1] == '\n') value [strlen(value)-1] = 0; if (!strcmp (token, pszJoystickMin)) sscanf (value, "%d,%d,%d,%d,%d,%d,%d", &cal [0].nMin, &cal [1].nMin, &cal [2].nMin, &cal [3].nMin, &cal [4].nMin, &cal [5].nMin, &cal [6].nMin); else if (!strcmp (token, pszJoystickMax)) sscanf (value, "%d,%d,%d,%d,%d,%d,%d", &cal [0].nMax, &cal [1].nMax, &cal [2].nMax, &cal [3].nMax, &cal [4].nMax, &cal [5].nMax, &cal [6].nMax); else if (!strcmp (token, pszJoystickCen)) sscanf (value, "%d,%d,%d,%d,%d,%d,%d", &cal [0].nCenter, &cal [1].nCenter, &cal [2].nCenter, &cal [3].nCenter, &cal [4].nCenter, &cal [5].nCenter, &cal [6].nCenter); } } cf.Close (); } JoySetCalVals (cal, sizeofa (cal)); return 0; }