Skip to content

Commit 3700326

Browse files
committed
Audio table decoding: Detect the audio table copy more liberally
Most or all Ravensburger GMEs have a duplicated Audio table. Most of them have an identical copy, but it seems not all. For those where the table is 80% equal, treat it like a copy (and throw away the extra information for now). It remains future work to make sense of this extra table.
1 parent 58b9bff commit 3700326

18 files changed

+36
-3166
lines changed

src/Commands.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ dumpInfo conf file = do
117117
(fst (head st)) (fst (last st))
118118
(length (filter (isNothing . snd) st)) (length st)
119119
printf "Audio table entries: %d\n" (length ttAudioFiles)
120-
when ttAudioFilesDoubles $ printf "Audio table repeated twice\n"
120+
printf "Audio table copy: %s\n" (show ttAudioFilesDoubles)
121121
printf "Binary tables entries: %d/%d/%d\n"
122122
(length ttBinaries1)
123123
(length ttBinaries2)

src/GMEParser.hs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -270,27 +270,34 @@ getBinaries = do
270270
binary <- getSegAt offset (BC.unpack desc) (getBS length)
271271
return (desc, binary)
272272

273-
getAudios :: Word32 -> SGet ([B.ByteString], Bool, Word8)
273+
getAudios :: Word32 -> SGet ([B.ByteString], Similarity, Word8)
274274
getAudios rawXor = do
275275
until <- lookAhead getWord32
276276
x <- case () of
277277
() | rawXor == knownRawXOR -> return knownXOR
278278
| otherwise -> lookAhead $ jumpTo until >> getXor
279279
offset <- bytesRead
280280
let n_entries = fromIntegral ((until - offset) `div` 8)
281-
at_doubled <- lookAhead $ do
282-
half1 <- getBS (n_entries * 8 `div` 2)
283-
half2 <- getBS (n_entries * 8 `div` 2)
284-
return $ half1 == half2
285-
let n_entries' | at_doubled = n_entries `div` 2
286-
| otherwise = n_entries
281+
similarity <- determine_similiarity <$> lookAhead (getBS (n_entries * 8))
282+
let n_entries' | Absent <- similarity = n_entries
283+
| otherwise = n_entries `div` 2
287284
decoded <- forM [0..n_entries'-1] $ \n -> do
288285
cypher x <$> indirectBS (show n)
289-
-- Fix segment
290-
when at_doubled $ lookAhead $ getSeg "Audio table copy" $
286+
-- pretend we read the rest too
287+
unless (similarity == Absent) $ lookAhead $ getSeg "Audio table copy" $
291288
replicateM_ (fromIntegral n_entries') (getWord32 >> getWord32)
292289

293-
return (decoded, at_doubled, x)
290+
return (decoded, similarity, x)
291+
where
292+
-- Fuzzy comparison: More than 80% the same?
293+
determine_similiarity bs
294+
| a == b = Equal
295+
| 5 * same >= 4 * n = Similar
296+
| otherwise = Absent
297+
where
298+
(a,b) = B.splitAt (B.length bs `div` 2) bs
299+
n = fromIntegral (B.length a)
300+
same = length [ () | (x,y) <- B.zip a b, x == y ]
294301

295302
getXor :: SGet Word8
296303
getXor = do
@@ -307,7 +314,7 @@ getXor = do
307314
getChecksum :: SGet Word32
308315
getChecksum = do
309316
l <- getLength
310-
getSegAt (l-4) "Checksum" $ getWord32
317+
getSegAt (l-4) "Checksum" getWord32
311318

312319
calcChecksum :: SGet Word32
313320
calcChecksum = do

src/TipToiYaml.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ ttYaml2tt no_date dir (TipToiYAML {..}) extCodes = do
884884
, ttGames = games
885885
, ttAudioFiles = files
886886
, ttAudioXor = knownXOR
887-
, ttAudioFilesDoubles = False
887+
, ttAudioFilesDoubles = Absent
888888
, ttMediaFlags = Nothing
889889
, ttChecksum = 0x00
890890
, ttChecksumCalc = 0x00

src/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ data Line r = Line Offset [Conditional r] [Command r] PlayList
6464

6565
type ProductID = Word32
6666

67+
data Similarity = Absent | Equal | Similar deriving (Show, Eq)
6768

6869
data TipToiFile = TipToiFile
6970
{ ttProductId :: ProductID
@@ -76,7 +77,7 @@ data TipToiFile = TipToiFile
7677
, ttScripts :: [(Word16, Maybe [Line ResReg])]
7778
, ttGames :: [Game]
7879
, ttAudioFiles :: [B.ByteString]
79-
, ttAudioFilesDoubles :: Bool
80+
, ttAudioFilesDoubles :: Similarity
8081
, ttAudioXor :: Word8
8182
, ttMediaFlags :: Maybe [Word16]
8283
, ttBinaries1 :: [(B.ByteString, B.ByteString)]

testsuite/expected/downloaded/Alle meine Tiere.gme.info.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Number of registers: 3
88
Initial registers: [0,0,0]
99
Initial sounds: [[18,25]]
1010
Scripts for OIDs from 4201 to 4282; 0/82 are disabled.
11-
Audio table entries: 1086
11+
Audio table entries: 543
12+
Audio table copy: Similar
1213
Binary tables entries: 0/0/0
1314
Single binary table entries: 1/1/1
1415
Special OIDs: 4210, 0

testsuite/expected/downloaded/Alle meine Tiere.gme.lint.txt

Lines changed: 0 additions & 539 deletions
Large diffs are not rendered by default.

testsuite/expected/downloaded/Dein Koerper und Du.gme.info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Initial registers: [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
99
Initial sounds: [[1447,317],[317]]
1010
Scripts for OIDs from 5670 to 9969; 3709/4300 are disabled.
1111
Audio table entries: 1448
12-
Audio table repeated twice
12+
Audio table copy: Equal
1313
Binary tables entries: 1/1/1
1414
Single binary table entries: 1/1/1
1515
Special OIDs: 9756, 0

testsuite/expected/downloaded/Duell-der-Superquizzer.gme.info.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Number of registers: 3
88
Initial registers: [1,0,0]
99
Initial sounds: [[29,44,108]]
1010
Scripts for OIDs from 4100 to 4300; 0/201 are disabled.
11-
Audio table entries: 4230
11+
Audio table entries: 2115
12+
Audio table copy: Similar
1213
Binary tables entries: 1/1/1
1314
Single binary table entries: 1/1/1
1415
Special OIDs: 4105, 0

testsuite/expected/downloaded/Duell-der-Superquizzer.gme.lint.txt

Lines changed: 0 additions & 2115 deletions
Large diffs are not rendered by default.

testsuite/expected/downloaded/Expedition Wissen - Aegypten.gme.info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Initial registers: [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
99
Initial sounds: [[907,908],[908]]
1010
Scripts for OIDs from 34 to 3583; 3018/3550 are disabled.
1111
Audio table entries: 909
12-
Audio table repeated twice
12+
Audio table copy: Equal
1313
Binary tables entries: 14/14/14
1414
Single binary table entries: 1/1/1
1515
Special OIDs: 3010, 3009

0 commit comments

Comments
 (0)