Last active
January 1, 2026 22:52
-
-
Save nathnolt/0d4f6aac3440a521b432bfecf1b8ca4b to your computer and use it in GitHub Desktop.
The Games Factory .gam 0C_Music.mus music file to midis converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The Games Factory 0C_Music.mus -> midi files | |
| // See the following tool for actually extracting the 0C_Music.mus file from a .gam file | |
| // https://kippykip.com/threads/cextract-the-games-factory-multimedia-fusion-game-extractor-unprotector.498/ | |
| // | |
| import fs from 'fs' | |
| const input = './0C_Music.mus' | |
| const buffer = fs.readFileSync(input) | |
| let chars = [] | |
| for(let i = 0; i < buffer.length; i++) { | |
| const value = buffer[i] | |
| const char = String.fromCharCode(value) | |
| chars.push(char) | |
| } | |
| const midiStartIndexes = findSections(chars, ['M', 'T', 'h', 'd']) | |
| // Array to store the result buffers with the MIDI files. | |
| let midiBuffers = [] | |
| for(let i = 0; i < midiStartIndexes.length; i++) { | |
| let startIndex = midiStartIndexes[i] | |
| let endIndex = midiStartIndexes[i + 1] | |
| const midiBuffer = buffer.subarray(startIndex, endIndex) | |
| midiBuffers.push(midiBuffer) | |
| } | |
| for(let i = 0; i < midiBuffers.length; i++) { | |
| const midiBuffer = midiBuffers[i] | |
| fs.writeFileSync(`./midi-${i}.mid`, midiBuffer, {encoding: null}) | |
| } | |
| console.log('done writing') | |
| // console.log(midiBuffers) | |
| // Find all starting indexes of the findArray within the fromArray | |
| function findSections(fromArray, findArray) { | |
| // Basic validation: if findArray is empty or larger than fromArray, it can't be found | |
| if (findArray.length === 0 || findArray.length > fromArray.length) { | |
| return undefined; | |
| } | |
| const results = []; | |
| // Loop through the array, but stop where the remaining length | |
| // is shorter than the array we are looking for. | |
| for (let i = 0; i <= fromArray.length - findArray.length; i++) { | |
| let match = true; | |
| // Check if the sequence starting at i matches findArray | |
| for (let j = 0; j < findArray.length; j++) { | |
| if (fromArray[i + j] !== findArray[j]) { | |
| match = false; | |
| break; | |
| } | |
| } | |
| if (match) { | |
| results.push(i); | |
| } | |
| } | |
| // Return the results array if it contains items, otherwise return undefined | |
| return results.length > 0 ? results : undefined; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment