Skip to content

Commit 619f675

Browse files
committed
Recognize our own magic hash
so that when we create GME files with MP3 files without a magic header, we do not have to guess the XOR value.
1 parent 159060d commit 619f675

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

src/Constants.hs

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ arithOpCode XOr = [0xF7, 0xFF]
1616
-- Neg is unary, hence a Command
1717
arithOpCode Set = [0xF9, 0xFF]
1818

19+
knownRawXOR :: Word32
20+
knownRawXOR = 0x00000039 -- from Bauernhof
21+
22+
knownXOR :: Word8
23+
knownXOR = 0xAD
1924

2025
fileMagics :: [(BC.ByteString, String)]
2126
fileMagics =

src/GMEParser.hs

+8-5
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,12 @@ getBinaries = do
238238
binary <- getSegAt offset (BC.unpack desc) (getBS length)
239239
return (desc, binary)
240240

241-
getAudios :: SGet ([B.ByteString], Bool, Word8)
242-
getAudios = do
241+
getAudios :: Word32 -> SGet ([B.ByteString], Bool, Word8)
242+
getAudios rawXor = do
243243
until <- lookAhead getWord32
244-
x <- lookAhead $ jumpTo until >> getXor
244+
x <- case () of
245+
() | rawXor == knownRawXOR -> return knownXOR
246+
| otherwise -> lookAhead $ jumpTo until >> getXor
245247
offset <- bytesRead
246248
let n_entries = fromIntegral ((until - offset) `div` 8)
247249
at_doubled <- lookAhead $ do
@@ -359,13 +361,14 @@ getSpecials = (,) <$> getWord16 <*> getWord16
359361
getTipToiFile :: SGet TipToiFile
360362
getTipToiFile = getSegAt 0x00 "Header" $ do
361363
ttScripts <- indirection "Scripts" getScripts
362-
(ttAudioFiles, ttAudioFilesDoubles, ttAudioXor) <- indirection "Media" getAudios
364+
ttRawXor <- getAt 0x001C getWord32
365+
(ttAudioFiles, ttAudioFilesDoubles, ttAudioXor) <- indirection "Media" (getAudios ttRawXor)
363366
_ <- getWord32 -- Usually 0x0000238b
364367
_ <- indirection "Additional script" getScript
365368
ttGames <- indirection "Games" $ indirections getWord32 "" getGame
366369
ttProductId <- getWord32
367370
ttInitialRegs <- indirection "Initial registers" getInitialRegs
368-
ttRawXor <- getWord32
371+
_ <- getWord32 -- raw Xor
369372
(ttComment, ttDate) <- do
370373
l <- getWord8
371374
c <- getBS (fromIntegral l)

src/TipToiYaml.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ ttYaml2tt dir (TipToiYAML {..}) extCodeMap = do
280280

281281
return $ (TipToiFile
282282
{ ttProductId = ttyProduct_Id
283-
, ttRawXor = 0x00000039 -- from Bauernhof
283+
, ttRawXor = knownRawXOR
284284
, ttComment = BC.pack (fromMaybe "created with tip-toi-reveng" ttyComment)
285285
, ttDate = BC.pack date
286286
, ttWelcome = welcome
287287
, ttInitialRegs = [fromMaybe 0 (M.lookup r initRegs) | r <- [0..maxReg]]
288288
, ttScripts = scripts'
289289
, ttGames = []
290290
, ttAudioFiles = files
291-
, ttAudioXor = 0xAD
291+
, ttAudioXor = knownXOR
292292
, ttAudioFilesDoubles = False
293293
, ttChecksum = 0x00
294294
, ttChecksumCalc = 0x00

0 commit comments

Comments
 (0)