public JWaveSystem loadWSYS(BeBinaryReader binStream, int Base) { var newWSYS = new JWaveSystem(); binStream.BaseStream.Position = Base; newWSYS.mOffset = (int)binStream.BaseStream.Position; if (binStream.ReadInt32() != WSYS) // Check if first 4 bytes are WSYS { throw new InvalidDataException("Data is not an WSYS"); } var wsysSize = binStream.ReadInt32(); // Read the size of the WSYS var wsysID = binStream.ReadInt32(); // Read WSYS ID var unk1 = binStream.ReadInt32(); // Unused? var waveINF = binStream.ReadInt32(); // Offset to WINF var waveBCT = binStream.ReadInt32(); // Offset to WBCT /* Should probably squish this into a different function. And I did. */ binStream.BaseStream.Position = waveINF + Base; // Seek to WINF relative to base. var winfoPointers = readWINF(binStream, Base); // Read the waveGroup pointers binStream.BaseStream.Position = waveBCT + Base; // Seek to the WBCT var wbctPointers = readWBCT(binStream, Base); // load the pointers for the wbct (Wave ID's) JWaveGroup[] WSYSGroups = new JWaveGroup[winfoPointers.Length]; // The count of waveInfo's determines the amount of groups -- there is one WINF entry per group JWaveScene[] WSYSScenes = new JWaveScene[wbctPointers.Length]; for (int i = 0; i < WSYSGroups.Length; i++) { binStream.BaseStream.Position = Base + winfoPointers[i]; // Seek to the wavegroup base. WSYSGroups[i] = readWaveGroup(binStream, Base); // load the WaveGroup } for (int i = 0; i < WSYSGroups.Length; i++) { var currentWG = WSYSGroups[i]; // After they've been loaded, we need to load their wave ID's binStream.BaseStream.Position = Base + wbctPointers[i]; // this is achieve by the WBCT, which points to a SCNE WSYSScenes[i] = new JWaveScene() { mOffset = (int)binStream.BaseStream.Position }; var scenes = loadScene(binStream, Base); // Load the SCNE object { binStream.BaseStream.Position = scenes[0] + Base; // The SCNE contains pointers to C-DF, C-EX, and C-ST -- we only know that C-DF works. var IDMap = loadC_DF(binStream, Base); // load the C_DF, which gives us an array of C_DF entries, containing awID and WaveID. WSYSScenes[i].CDFData = IDMap; } } newWSYS.id = wsysID; // We loaded the ID from above, store it newWSYS.Scenes = WSYSScenes; newWSYS.Groups = WSYSGroups; // We need to store the groups too, so let's do that. return(newWSYS); }
public JWaveSystem loadWSYS(BeBinaryReader binStream, int Base) { var newWSYS = new JWaveSystem(); binStream.BaseStream.Position = Base; if (binStream.ReadInt32() != WSYS) // Check if first 4 bytes are WSYS { throw new InvalidDataException("Data is not an WSYS"); } var wsysSize = binStream.ReadInt32(); // Read the size of the WSYS var wsysID = binStream.ReadInt32(); // Read WSYS ID var unk1 = binStream.ReadInt32(); // Unused? var waveINF = binStream.ReadInt32(); // Offset to WINF var waveBCT = binStream.ReadInt32(); // Offset to WBCT /* Should probably squish this into a different function. And I did. */ binStream.BaseStream.Position = waveINF + Base; // Seek to WINF relative to base. var winfoPointers = readWINF(binStream, Base); // Read the waveGroup pointers binStream.BaseStream.Position = waveBCT + Base; // Seek to the WBCT var wbctPointers = readWBCT(binStream, Base); // load the pointers for the wbct (Wave ID's) JWaveGroup[] WSYSGroups = new JWaveGroup[winfoPointers.Length]; // The count of waveInfo's determines the amount of groups -- there is one WINF entry per group. newWSYS.WaveTable = new Dictionary <int, JWave>(); for (int i = 0; i < WSYSGroups.Length; i++) { binStream.BaseStream.Position = Base + winfoPointers[i]; // Seek to the wavegroup base. WSYSGroups[i] = readWaveGroup(binStream, Base); // load the WaveGroup } for (int i = 0; i < WSYSGroups.Length; i++) { var currentWG = WSYSGroups[i]; // After they've been loaded, we need to load their wave ID's binStream.BaseStream.Position = Base + wbctPointers[i]; // this is achieve by the WBCT, which points to a SCNE var scenes = loadScene(binStream, Base); // Load the SCNE object { binStream.BaseStream.Position = scenes[0] + Base; // The SCNE contains pointers to C-DF, C-EX, and C-ST -- we only know that C-DF works. var IDMap = loadC_DF(binStream, Base); // load the C_DF, which gives us an array of C_DF entries, containing awID and WaveID. for (int b = 0; b < IDMap.Length; b++) // We need to loop over the map of ID's { currentWG.Waves[b].id = IDMap[b].waveid; // SCNE and WaveGroup are 1 to 1, meanin the first entry in one lines up with the other. // So we'll want to move the waveid into the wave object itself for convience. currentWG.WaveByID[IDMap[b].waveid] = currentWG.Waves[b]; // Basically making a copy of the wave object, so it can be found by its ID instead of entry index. newWSYS.WaveTable[IDMap[b].waveid] = currentWG.Waves[b]; // TODO: Add Wavegroup.load for wsys, not all waves are loaded all the time. } } } newWSYS.id = wsysID; // We loaded the ID from above, store it newWSYS.Groups = WSYSGroups; // We need to store the groups too, so let's do that. return(newWSYS); }
private JWaveGroup readWaveGroup(BeBinaryReader binStream, int Base) { var newWG = new JWaveGroup(); // Create new Wavegroup object newWG.mOffset = (int)binStream.BaseStream.Position; newWG.awFile = readArchiveName(binStream); // Exec helper functionn, which reads 0x70 bytes and trims off the fat. var waveCount = binStream.ReadInt32(); // Read the wave count int[] WaveOffsets = Helpers.readInt32Array(binStream, waveCount); // Read waveCount int32's newWG.Waves = new JWaveDescriptor[waveCount]; // make an array with all of the wave counts, this is to store the waves we will read for (int i = 0; i < waveCount; i++) { binStream.BaseStream.Position = Base + WaveOffsets[i]; // Seek to the offset of each eave newWG.Waves[i] = loadWave(binStream, Base); // Then tell it to load. } return(newWG); }
private JWaveGroup readWaveGroup(BeBinaryReader binStream, int Base) { var newWG = new JWaveGroup(); // Create new Wavegroup object newWG.WaveByID = new Dictionary <int, JWave>(); // Initialize the dictionary (map) for the wave id's (used later) newWG.awFile = readArchiveName(binStream); // Exec helper functionn, which reads 0x70 bytes and trims off the fat. var waveCount = binStream.ReadInt32(); // Read the wave count int[] WaveOffsets = Helpers.readInt32Array(binStream, waveCount); // Read waveCount int32's newWG.Waves = new JWave[waveCount]; // make an array with all of the wave counts, this is to store the waves we will read for (int i = 0; i < waveCount; i++) { binStream.BaseStream.Position = Base + WaveOffsets[i]; // Seek to the offset of each eave newWG.Waves[i] = loadWave(binStream, Base); // Then tell it to load. newWG.Waves[i].wsysFile = newWG.awFile; } return(newWG); }