#! /bin/bash game=$1 #Available games: #1 lang=$2 #Available languages: #en #jp append=$3 #debug [[ $game && $lang ]] || { echo wrong arguments; exit; } for msd in [sS]0??.MSD; do oldmusic= chara= chima= multi= shortmsd=${msd#?} shortmsd=${shortmsd%.MSD} { [[ $lang == en ]] && LANG=C sed ' s/\x81\x99/HARTEMOTe/g s/\x81\xf4/NOTEEMOTe/g s/\x81\x60/LONGTILDe/g s/\x81\x75/QUOTEOPEn/g s/\x81\x63/ELIPSEs/g s/\x81\x76/QUOTECLOSe/g s/\x81\x40\x81\x40/NEWLINe/g s/\x81\x40\x82\xa8\x82\xb5.*/OSHIMAi/' "$msd" [[ $lang == jp ]] && LANG=C sed ' s/\x81\x99/HEARTEMOTE./g s/\x81\xf4/REMOVETHIS&/g s/\x81\x60/LONGTILDE./g s/\x81\x75/REMOVETHIS&/g s/\x81\x63/REMOVETHIS&/g s/\x81\x76/REMOVETHIS&/g s/\x81\x40\x81\x40/NEWLINe/g' "$msd" } | strings -eS -n 3 | { [[ $lang == en ]] && sed ' s/- *NEWLINe/-/g s/NEWLINe/ /g s/ */ /g s/"/\\&/g;s/^ // s/^[\\*A-Z.].*[a-z.].*/"&"/ s/^[^"].*\.\.\..*/"&"/ s/HARTEMOTe/♡/g s/NOTEEMOTe/♪/g s/LONGTILDe/~/g s/QUOTEOPEn/ “/g s/QUOTECLOSe/” /g s/ELIPSEs/…/g s/OSHIMAi/The End/g' [[ $lang == jp ]] && iconv -c -f cp932 -t utf8 | sed ' #s/!QUOTEOPEn[^!]*Japanese[^!]*!QUOTECLOSe/Japanese\n/g s/REMOVETHIS//g s/- *NEWLINe/-/g s/NEWLINe/ /g s/ */ /g s/"/\\&/g;s/^ // s/^[\\*A-Z.].*[a-z.].*/"&"/ s/^[^"].*\.\.\..*/"&"/ s/HEARTEMOTE\./♡/g #s/NOTEEMOTe/♪/g s/LONGTILDE\./~/g #s/QUOTEOPEn/ “/g #s/QUOTECLOSe/” /g #s/ELIPSEs/…/g #s/OSHIMAi/The End/g /^$/d /^.$/d' } | sed ' s/^CU\([0-9]*\)/show cu\1/ s/^bg.*/scene &/ s/^\(EV[0-9]\+\)P\(.*\)/scene \1p\2/ s/^EV[0-9]\+.*/scene &/ s/^scene EV12$/scene ev12/ s/^BLACK$/scene &\npause 1.0/ s/^SE[0-9]\+.*/play sound "common\/&.ogg"/ #s/^M[0-9]\+.*/stop music fadeout 1.0\nplay music "common\/&.ogg"/ s/^[A-Z]\{4\}[0-9]\+[a-zA-Z]*$/voice "&"/ s/^t\([a-z][a-z]\).*/show \1 &/ s/ -\([a-zA-Z]\+\)-\([. ]\)/ {i}\1{\/i}\2/g' | grep -v $'\xff\xff\nDAMMY' | sed 's/^[^"a-zA-Z]\+$/"&"/ 2{s/^".*"/$ save_name = &/;t;i\ #Warning: Chapter title not on line 2. }' | sed ' /^show/{N;s/\(show.*\)\n\(show.*\)/\1 at l\n\2 at r/} /^voice/{N;s/\(voice "\(....\).*\)\n\(".*\)/\1\n\2 \3\n/ s/YUNA "/y "/ s/NANA "/n "/ s/GALA "/ga "/ s/GALB "/gb "/ s/GALC "/gc "/ s/KYOS "/tt "/ } #/^GS_EN_NS$/{N;s/^\(.*\)\n\(.*\)$/\2\n\1/} /^scene EV/{N;s/\(.*\)\n\(GS_EN_NS\)$/\2\n\1/}' | while read -r; do # echo -n "$oldchara:$REPLY:$scene_after_cu: " if [[ "$REPLY" =~ ^scene ]]; then [[ "$REPLY" == "$scene" ]] && identical_scenes=yes scene=$REPLY [[ "$chara" ]] && { oldchara=newscene oldchima=newscene oldmulti=newscene } fi if [[ "$REPLY" =~ ^M[0-9][0-9]+.* ]]; then currentmusic=$REPLY [[ "$oldmusic" != "$currentmusic" ]] && { echo 'stop music fadeout 1.0' REPLY='play music "common/'$currentmusic'.ogg"' } || REPLY="#Music already playing: $REPLY" oldmusic=$currentmusic fi if [[ "$REPLY" =~ ^show[[:blank:]]\ ([a-z][a-z][0-9]*)[[:blank:]]?\ (t[^[:blank:]]*)?[[:blank:]]?\ (.*) ]] then chara=${BASH_REMATCH[1]} chima=${BASH_REMATCH[2]} multi=${BASH_REMATCH[3]} if [[ $multi ]]; then while true; do echo "$REPLY" read -r [[ "$REPLY" =~ ^show[[:blank:]]\ ([a-z][a-z])[[:blank:]]\ (t[^[:blank:]]*)[[:blank:]]?\ (.*) ]] || { echo Error 1: Multi character bad format; exit; } chima+=\ ${BASH_REMATCH[2]} multi=${BASH_REMATCH[3]} [[ "$multi" =~ at\ r$ ]] && break done fi if [[ "$oldchara" =~ ^cu ]]; then # echo hide $oldchara [[ $multi ]] && echo 'Error 4, multi after cu' echo "$scene" echo "$REPLY at center" read -r [[ "$REPLY" != GS_CLR ]] && echo 'Error 2, expected GS_CLR' REPLY="with $REPLY" #what if after cu comes a multi elif [[ "$chara" =~ ^cu ]]; then echo "$scene" echo "$REPLY" read -r ! [[ "$REPLY" =~ ^GS ]] && echo 'Error 3, expected a GS' REPLY="with $REPLY" elif [[ ! "$multi" && ( -n "$oldchara" && "$oldchara" != "$chara" || "$oldmulti" ) ]]; then for img in $oldchima; do [[ "$img" =~ ^t([a-z][a-z]).* ]] && echo "hide ${BASH_REMATCH[1]} $img" done # if [[ ! "$oldmulti" ]]; then echo "$REPLY at center" REPLY='with dissolve' # fi elif [[ -z "$oldchara" ]]; then REPLY+=' with dissolve' elif [[ "$multi" && ! "$oldmulti" ]]; then echo "$REPLY" REPLY='with dissolve' fi oldchara=$chara oldchima=$chima oldmulti=$multi fi [[ "$identical_scenes" == yes ]] && identical_scenes=no || echo "$REPLY" done | sed '/^"/{:more;N;s/\n[^"]/&/;Tmore;s/\n[^"]/\n&/}' | sed -r '/^(GS_(CUD|EN)|scene)/{N; s/scene.*(CUD|EN_NS)/&/;t order1 s/(CUD|EN_NS).*scene/&/;t order2 b :order1;s/\n/\nwith /;b :order2;s/(.*)\n(.*)/\2\nwith \1/ }' | { [[ $lang == jp ]] && sed ' # /^"."$/d /^voice "NANA0210"/i\ voice "YUNA0178"\ y "「ほんと? じゃあ、お姉さまって呼んでくれる?」"\ ' [[ $lang == en ]] && cat } | sed ' 1i\ label s'$shortmsd': $a\ jump s'$(printf '%03d' $((${shortmsd//0/} +1)))' /^main$/d /^scene ev12$/i\ #TODO: ev12 is a scrolling image /^S[0-9]\{3\}$/d /^MSCENARIO/d /^GS/s/^/#/ /^sel/{s/^/#/;a\ #TODO: BRANCH } #$a\ # scene BLACK s/^/ / s/- \(chaa*n\)/-\1/g s/- \(samaa*\)/-\1/g s/- \(senpaa*\)/-\1/g' | sed 's/jump s016/jump ending/' | uniq > "strings_$msd.txt$3" done