Skip to content

Commit

Permalink
Audio table decoding: Detect the audio table copy more liberally
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nomeata committed Nov 30, 2020
1 parent 806be99 commit 0441235
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 3,166 deletions.
2 changes: 1 addition & 1 deletion src/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ dumpInfo conf file = do
(fst (head st)) (fst (last st))
(length (filter (isNothing . snd) st)) (length st)
printf "Audio table entries: %d\n" (length ttAudioFiles)
when ttAudioFilesDoubles $ printf "Audio table repeated twice\n"
printf "Audio table copy: %s\n" (show ttAudioFilesDoubles)
printf "Binary tables entries: %d/%d/%d\n"
(length ttBinaries1)
(length ttBinaries2)
Expand Down
29 changes: 18 additions & 11 deletions src/GMEParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,27 +270,34 @@ getBinaries = do
binary <- getSegAt offset (BC.unpack desc) (getBS length)
return (desc, binary)

getAudios :: Word32 -> SGet ([B.ByteString], Bool, Word8)
getAudios :: Word32 -> SGet ([B.ByteString], Similarity, Word8)
getAudios rawXor = do
until <- lookAhead getWord32
x <- case () of
() | rawXor == knownRawXOR -> return knownXOR
| otherwise -> lookAhead $ jumpTo until >> getXor
offset <- bytesRead
let n_entries = fromIntegral ((until - offset) `div` 8)
at_doubled <- lookAhead $ do
half1 <- getBS (n_entries * 8 `div` 2)
half2 <- getBS (n_entries * 8 `div` 2)
return $ half1 == half2
let n_entries' | at_doubled = n_entries `div` 2
| otherwise = n_entries
similarity <- determine_similiarity <$> lookAhead (getBS (n_entries * 8))
let n_entries' | Absent <- similarity = n_entries
| otherwise = n_entries `div` 2
decoded <- forM [0..n_entries'-1] $ \n -> do
cypher x <$> indirectBS (show n)
-- Fix segment
when at_doubled $ lookAhead $ getSeg "Audio table copy" $
-- pretend we read the rest too
unless (similarity == Absent) $ lookAhead $ getSeg "Audio table copy" $
replicateM_ (fromIntegral n_entries') (getWord32 >> getWord32)

return (decoded, at_doubled, x)
return (decoded, similarity, x)
where
-- Fuzzy comparison: More than 80% the same?
determine_similiarity bs
| a == b = Equal
| 5 * same >= 4 * n = Similar
| otherwise = Absent
where
(a,b) = B.splitAt (B.length bs `div` 2) bs
n = fromIntegral (B.length a)
same = length [ () | (x,y) <- B.zip a b, x == y ]

getXor :: SGet Word8
getXor = do
Expand All @@ -307,7 +314,7 @@ getXor = do
getChecksum :: SGet Word32
getChecksum = do
l <- getLength
getSegAt (l-4) "Checksum" $ getWord32
getSegAt (l-4) "Checksum" getWord32

calcChecksum :: SGet Word32
calcChecksum = do
Expand Down
2 changes: 1 addition & 1 deletion src/TipToiYaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ ttYaml2tt no_date dir (TipToiYAML {..}) extCodes = do
, ttGames = games
, ttAudioFiles = files
, ttAudioXor = knownXOR
, ttAudioFilesDoubles = False
, ttAudioFilesDoubles = Absent
, ttMediaFlags = Nothing
, ttChecksum = 0x00
, ttChecksumCalc = 0x00
Expand Down
3 changes: 2 additions & 1 deletion src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data Line r = Line Offset [Conditional r] [Command r] PlayList

type ProductID = Word32

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

data TipToiFile = TipToiFile
{ ttProductId :: ProductID
Expand All @@ -76,7 +77,7 @@ data TipToiFile = TipToiFile
, ttScripts :: [(Word16, Maybe [Line ResReg])]
, ttGames :: [Game]
, ttAudioFiles :: [B.ByteString]
, ttAudioFilesDoubles :: Bool
, ttAudioFilesDoubles :: Similarity
, ttAudioXor :: Word8
, ttMediaFlags :: Maybe [Word16]
, ttBinaries1 :: [(B.ByteString, B.ByteString)]
Expand Down
3 changes: 2 additions & 1 deletion testsuite/expected/downloaded/Alle meine Tiere.gme.info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Number of registers: 3
Initial registers: [0,0,0]
Initial sounds: [[18,25]]
Scripts for OIDs from 4201 to 4282; 0/82 are disabled.
Audio table entries: 1086
Audio table entries: 543
Audio table copy: Similar
Binary tables entries: 0/0/0
Single binary table entries: 1/1/1
Special OIDs: 4210, 0
Expand Down
539 changes: 0 additions & 539 deletions testsuite/expected/downloaded/Alle meine Tiere.gme.lint.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Initial sounds: [[1447,317],[317]]
Scripts for OIDs from 5670 to 9969; 3709/4300 are disabled.
Audio table entries: 1448
Audio table repeated twice
Audio table copy: Equal
Binary tables entries: 1/1/1
Single binary table entries: 1/1/1
Special OIDs: 9756, 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Number of registers: 3
Initial registers: [1,0,0]
Initial sounds: [[29,44,108]]
Scripts for OIDs from 4100 to 4300; 0/201 are disabled.
Audio table entries: 4230
Audio table entries: 2115
Audio table copy: Similar
Binary tables entries: 1/1/1
Single binary table entries: 1/1/1
Special OIDs: 4105, 0
Expand Down
2,115 changes: 0 additions & 2,115 deletions testsuite/expected/downloaded/Duell-der-Superquizzer.gme.lint.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Initial sounds: [[907,908],[908]]
Scripts for OIDs from 34 to 3583; 3018/3550 are disabled.
Audio table entries: 909
Audio table repeated twice
Audio table copy: Equal
Binary tables entries: 14/14/14
Single binary table entries: 1/1/1
Special OIDs: 3010, 3009
Expand Down
2 changes: 1 addition & 1 deletion testsuite/expected/downloaded/Leserabe Drache.gme.info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Initial sounds: [[1007,1008]]
Scripts for OIDs from 1008 to 5547; 3755/4540 are disabled.
Audio table entries: 1009
Audio table repeated twice
Audio table copy: Equal
Binary tables entries: 12/12/12
Single binary table entries: 1/1/1
Special OIDs: 4902, 4901
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Number of registers: 41
Initial registers: [1,99,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,0,0,0,0,0,0,0,0,0,0]
Initial sounds: [[283,342]]
Scripts for OIDs from 113 to 9516; 9230/9404 are disabled.
Audio table entries: 978
Audio table entries: 489
Audio table copy: Similar
Binary tables entries: 9/9/9
Single binary table entries: 1/1/1
Special OIDs: 9307, 9306
Expand Down
Loading

0 comments on commit 0441235

Please sign in to comment.