diff --git a/ports/iosas/Isles of Sea and Sky.sh b/ports/iosas/Isles of Sea and Sky.sh
new file mode 100644
index 0000000000..cd5b75667b
--- /dev/null
+++ b/ports/iosas/Isles of Sea and Sky.sh
@@ -0,0 +1,118 @@
+#!/bin/bash
+
+XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
+
+if [ -d "/opt/system/Tools/PortMaster/" ]; then
+ controlfolder="/opt/system/Tools/PortMaster"
+elif [ -d "/opt/tools/PortMaster/" ]; then
+ controlfolder="/opt/tools/PortMaster"
+elif [ -d "$XDG_DATA_HOME/PortMaster/" ]; then
+ controlfolder="$XDG_DATA_HOME/PortMaster"
+else
+ controlfolder="/roms/ports/PortMaster"
+fi
+
+source $controlfolder/control.txt
+source $controlfolder/device_info.txt
+[ -f "${controlfolder}/mod_${CFW_NAME}.txt" ] && source "${controlfolder}/mod_${CFW_NAME}.txt"
+get_controls
+
+# Setup permissions
+$ESUDO chmod 666 /dev/tty1
+$ESUDO chmod 666 /dev/uinput
+echo "Loading, please wait... (might take a while!)" > /dev/tty0
+
+# Variables
+GAMEDIR="/$directory/ports/iosas"
+BITRATE=64
+
+cd $GAMEDIR
+> "$GAMEDIR/log.txt" && exec > >(tee "$GAMEDIR/log.txt") 2>&1
+
+$ESUDO chmod 777 "$GAMEDIR/gmloadernext"
+$ESUDO chmod 777 "$GAMEDIR/libs/splash"
+$ESUDO chmod 777 "$GAMEDIR/tools/gm-Ktool.py"
+
+# Exports
+export LD_LIBRARY_PATH="$GAMEDIR/libs:$GAMEDIR/tools/lib:$LD_LIBRARY_PATH"
+export SDL_GAMECONTROLLERCONFIG="$sdl_controllerconfig"
+export PATH="$GAMEDIR/tools:$PATH"
+
+# Display loading splash
+if [ -f "$GAMEDIR/game.droid" ]; then
+ $ESUDO ./libs/splash "splash.png" 1
+ $ESUDO ./libs/splash "splash.png" 8000
+fi
+
+# Functions
+install() {
+ echo "Performing first-run setup..." > $CUR_TTY
+ # Purge unneeded files
+ rm -rf assets/*.exe assets/*.dll assets/.gitkeep
+ # Rename data.win
+ echo "Moving game files..." > $CUR_TTY
+ mv "./assets/data.win" "./game.droid"
+ mv assets/* ./
+ rmdir assets
+ apply_patch
+ compress_audio || return 1
+ # Only do this during the install step so the user can turn it back on if they wish post-install
+ if [ $DEVICE_RAM -lt 2 ]; then
+ sed -i "s/^IdolSFX=[0-9]\+/IdolSFX=0/" "$GAMEDIR/pm-config.ini"
+ fi
+}
+
+apply_patch() {
+ echo "Applying patch..." > $CUR_TTY
+ if [ -f "$controlfolder/xdelta3" ]; then
+ error=$("$controlfolder/xdelta3" -d -s "$GAMEDIR/game.droid" "$GAMEDIR/tools/patch_idol_sfx.xdelta" "$GAMEDIR/game2.droid" 2>&1)
+ if [ $? -eq 0 ]; then
+ rm -rf "$GAMEDIR/game.droid"
+ mv "$GAMEDIR/game2.droid" "$GAMEDIR/game.droid"
+ echo "Patch applied successfully." > $CUR_TTY
+ else
+ echo "Failed to apply patch. Error: $error" > $CUR_TTY
+ rm -f "$GAMEDIR/game2.droid"
+ return 1
+ fi
+ else
+ echo "Error: xdelta3 not found in $controlfolder. Try updating PortMaster." > $CUR_TTY
+ return 1
+ fi
+}
+
+compress_audio() {
+ echo "Compressing audio. The process will take 5-10 minutes" > $CUR_TTY
+
+ gm-Ktool.py -b $BITRATE "$GAMEDIR/game.droid" "$GAMEDIR/game2.droid"
+
+ if [ $? -eq 0 ]; then
+ rm -rf "$GAMEDIR/game.droid"
+ mv "$GAMEDIR/game2.droid" "$GAMEDIR/game.droid"
+ echo "Audio compression applied successfully." > $CUR_TTY
+ else
+ echo "Audio compression failed." > $CUR_TTY
+ rm -f "$GAMEDIR/game2.droid"
+ return 1
+ fi
+}
+
+if [ ! -f "$GAMEDIR/game.droid" ]; then
+ $ESUDO ./libs/splash "patching_splash.png" 1
+ $ESUDO ./libs/splash "patching_splash.png" 12000 &
+ install || return 1
+fi
+
+# Font replacements
+if [ -f "localization_fonts.csv" ]; then
+ sed -i 's/malgun\.ttf/BMDOHYEON_ttf.ttf/g' localization_fonts.csv # Korean
+fi
+
+# Assign gptokeyb and load the game
+$GPTOKEYB "gmloadernext" -c "control.gptk" &
+./gmloadernext game.apk
+
+# Kill processes
+$ESUDO kill -9 $(pidof gptokeyb)
+$ESUDO systemctl restart oga_events &
+printf "\033c" > /dev/tty0
diff --git a/ports/iosas/README.md b/ports/iosas/README.md
new file mode 100644
index 0000000000..5bd09dd57c
--- /dev/null
+++ b/ports/iosas/README.md
@@ -0,0 +1,44 @@
+## Isles of Sea and Sky -- PortMaster Edition
+Isles of Sea and Sky is a sokoban block puzzle game with Zelda-like elements and a stunning soundtrack. With a lot of effort, this game is able to be run on small-arm linux handhelds using a Game Maker compatibility layer called GMLoader-Next and some patches to reduce memory and cpu usage.
+
+
+
+
+
+ Isles of Sea and Sky Launch Trailer
+
+
+
+ |
+
+
+
+ |
+
+
+
+
+## Installation
+Add your game data from your Steam installation to `ports/iosas/assets`. First-time run will handle sorting data.
+
+## Default Gameplay Controls
+| Button | Action |
+|--|--|
+|START|Menus|
+|SELECT|Map|
+|D-PAD / Analog|Move|
+|L1|Undo|
+|R1|Reset room|
+
+## Config
+The xdelta patch enables `pm-config.ini`, which has some performance options. Testing found that `FrameSkip=40` works pretty well for the H700 chip. For no stuttering at all, you can set `IdolSFX=0` to turn off the special effect that bogs down the cpu.
+
+## Importing / Exporting Save Data
+Steam saves are located at `\AppData\Local\IslesOfSeaAndSky` on Windows. Copy `save_v1_000.dat` or similar to `ports/iosas` to use it. To export save data to your Steam install, do the reverse.
+
+## Thanks
+Cicada Games -- The game and [press kit materials](https://islesofseaandsky.com/press-kit) used to create the splash screens
+Cyril "kotzebuedog" Delétré -- The phenomenal audio patch that makes this port possible
+nate -- Custom loading splash engine
+JohnnyOnFlame -- GMLoaderNext
+Testers and Devs from the PortMaster Discord
diff --git a/ports/iosas/cover.png b/ports/iosas/cover.png
new file mode 100644
index 0000000000..e6233e43c9
Binary files /dev/null and b/ports/iosas/cover.png differ
diff --git a/ports/iosas/gameinfo.xml b/ports/iosas/gameinfo.xml
new file mode 100644
index 0000000000..37213cc1ce
--- /dev/null
+++ b/ports/iosas/gameinfo.xml
@@ -0,0 +1,11 @@
+
+
+
+ ./Isles of Sea and Sky.sh
+ Isles of Sea and Sky
+ A fantastic, oceanic, open world puzzle adventure. Solve innovative block puzzles while unearthing a mystifying story, gaining new friends that change the puzzle landscape, and unlocking powers that provide more options for how you choose to progress through the enigmatic Isles of Sea and Sky.
+ 20240522
+ Cicada Games, Gamera Games
+ ./iosas/cover.png
+
+
diff --git a/ports/iosas/iosas/BMDOHYEON_ttf.ttf b/ports/iosas/iosas/BMDOHYEON_ttf.ttf
new file mode 100644
index 0000000000..358e6c8b59
Binary files /dev/null and b/ports/iosas/iosas/BMDOHYEON_ttf.ttf differ
diff --git a/ports/iosas/iosas/LICENSE_bmdohyeon.txt b/ports/iosas/iosas/LICENSE_bmdohyeon.txt
new file mode 100644
index 0000000000..de585f5ca1
--- /dev/null
+++ b/ports/iosas/iosas/LICENSE_bmdohyeon.txt
@@ -0,0 +1,54 @@
+Baedal Minjok Font License Policy
+---------------------------------
+
+The intellectual property rights of Hanna, Hanna Air, Hanna Pro, Jua, Dohyeon, Yeonsung, KirangHaerang, Euljiro, and Euljiro 10 Years Later, Baemin Geullim, Baemin Euljiro OraeOrae fonts are held by Woowa Brothers.
+
+Fonts distributed free of charge by Baedal Minjok (Hanna, Jua, Dohyeon, Yeonsung, KirangHaerang, Hanna Air, Hanna Pro, Euljiro, Euljiro 10 Years Later, Baemin Geullim, Baemin Euljiro OraeOrae) can be modified and changed freely and used by both individual and corporate users for commercial or non- profit purposes.
+
+However, please note that sales of the font file (OTF/TTF) is prohibited.
+
+- Permitted use: Commercial/non-commercial products such as signboards, banners, brochures, posters, books, magazines, business cards, stickers, packages, goods, webpages, advertisement banners, e-brochures, video captions, movies, TV advertisements, webcomics, game UI, app UI, newsletters, online magazines, presentations, e-books, messaging/chat stickers, logos, marks, newspaper advertisements, magazine advertisements, print advertisements, cup sleeves, hand fans, wrapping paper, mobile phone cases, notebooks, bags, shoes, and clothing.
+- Prohibited use: Paid sales of font files (OTF/TTF)
+Images of prints, advertisements (including online advertisements), and other products using free fonts distributed by Baemin (Hanna, Jua, Dohyeon, Yeonsung, KirangHaerang, Hanna Air, Hanna Pro, Euljiro, Euljiro 10 Years Later, Baemin Geullim, Baemin Euljiro OraeOrae) may be used for the company’s data collection and research purposes. If you wish to opt out of such use, please feel free to contact our Customer Service Center (+82-1600-0987 / CS@woowahan.com).
+
+Provided that the full text of the "Intellectual Property Guide and License" below is shown, the fonts may be bundled, redistributed, or sold with other software.
+
+Baedal Minjok Font License Policy
+Copyright © 2013, Woowa Brothers Corporation (https://www.woowahan.com), with Reserved Font Name BM HANNA 11yrs old, BM HANNA 11yrs old OTF, BMHANNAAir_otf, BMHANNAAir_ttf, BMHANNAPro_otf, BMHANNAPro_ttf, BM JUA_TTF, BM JUA_OTF, BM DoHyeon, BM DoHyeon OTF, BM YEONSUNG, BM YEONSUNG OTF, BM KIRANGHAERANG, BM KIRANGHAERANG OTF, BMEULJIRO, BMEULJIROTTF, BM EULJITO 10 YEARS LATER, BM EULJITO 10 YEARS LATER TTF, BMEuljirooraeoraeOTF.
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+
+This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL
+
+SIL OPEN FONT LICENSE
+Version 1.1 - 26 February 2007
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide development of collaborative font projects, to support the font creation efforts of academic and linguistic communities, and to provide a free and open framework in which fonts may be shared and improved in partnership with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and redistributed freely as long as they are not sold by themselves. The fonts, including any derivative works, can be bundled, embedded, redistributed and/or sold with any software provided that any reserved names are not used by derivative works. The fonts and derivatives, however, cannot be released under any other type of license. The requirement for fonts to remain under this license does not apply to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright Holder(s) under this license and clearly marked as such. This may include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting, or substituting — in part or in whole — any of the components of the Original Version, by changing formats or by porting the Font Software to a new environment.
+
+"Author" refers to any designer, engineer, programmer, technical writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining a copy of the Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the Font Software, subject to the following conditions:
+
+1. Neither the Font Software nor any of its individual components, in Original or Modified Versions, may be sold by itself.
+2. Original or Modified Versions of the Font Software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
+3. No Modified Version of the Font Software may use the Reserved Font Name(s) unless explicit written permission is granted by the corresponding Copyright Holder. This restriction only applies to the primary font name as presented to the users.
+4. The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall not be used to promote, endorse or advertise any Modified Version, except to acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with their explicit written permission.
+5. The Font Software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
+TERMINATION
+This license becomes null and void if any of the above conditions are not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
\ No newline at end of file
diff --git a/ports/iosas/iosas/assets/.gitkeep b/ports/iosas/iosas/assets/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/ports/iosas/iosas/control.gptk b/ports/iosas/iosas/control.gptk
new file mode 100644
index 0000000000..a96c3d0cee
--- /dev/null
+++ b/ports/iosas/iosas/control.gptk
@@ -0,0 +1,24 @@
+back = \"
+start = \"
+up = \"
+down = \"
+left = \"
+right = \"
+a = \"
+b = \"
+x = \"
+y = \"
+l1 = \"
+l2 = \"
+l3 = \"
+r1 = \"
+r2 = \"
+r3 = \"
+left_analog_up = \"
+left_analog_down = \"
+left_analog_left = \"
+left_analog_right = \"
+right_analog_up = \"
+right_analog_down = \"
+right_analog_left = \"
+right_analog_right = \"
\ No newline at end of file
diff --git a/ports/iosas/iosas/game.apk b/ports/iosas/iosas/game.apk
new file mode 100644
index 0000000000..bcdc2eb9ba
Binary files /dev/null and b/ports/iosas/iosas/game.apk differ
diff --git a/ports/iosas/iosas/gmloadernext b/ports/iosas/iosas/gmloadernext
new file mode 100644
index 0000000000..0215c1ac5a
Binary files /dev/null and b/ports/iosas/iosas/gmloadernext differ
diff --git a/ports/iosas/iosas/lib/arm64-v8a/libc++_shared.so b/ports/iosas/iosas/lib/arm64-v8a/libc++_shared.so
new file mode 100644
index 0000000000..268934f5b3
Binary files /dev/null and b/ports/iosas/iosas/lib/arm64-v8a/libc++_shared.so differ
diff --git a/ports/iosas/iosas/lib/arm64-v8a/libcompiler_rt.so b/ports/iosas/iosas/lib/arm64-v8a/libcompiler_rt.so
new file mode 100644
index 0000000000..f167a0d011
Binary files /dev/null and b/ports/iosas/iosas/lib/arm64-v8a/libcompiler_rt.so differ
diff --git a/ports/iosas/iosas/lib/arm64-v8a/libm.so b/ports/iosas/iosas/lib/arm64-v8a/libm.so
new file mode 100644
index 0000000000..2af51edd93
Binary files /dev/null and b/ports/iosas/iosas/lib/arm64-v8a/libm.so differ
diff --git a/ports/iosas/iosas/lib/armeabi-v7a/libc++_shared.so b/ports/iosas/iosas/lib/armeabi-v7a/libc++_shared.so
new file mode 100644
index 0000000000..ef2f3501e8
Binary files /dev/null and b/ports/iosas/iosas/lib/armeabi-v7a/libc++_shared.so differ
diff --git a/ports/iosas/iosas/lib/armeabi-v7a/libcompiler_rt.so b/ports/iosas/iosas/lib/armeabi-v7a/libcompiler_rt.so
new file mode 100644
index 0000000000..8747b729b8
Binary files /dev/null and b/ports/iosas/iosas/lib/armeabi-v7a/libcompiler_rt.so differ
diff --git a/ports/iosas/iosas/lib/armeabi-v7a/libm.so b/ports/iosas/iosas/lib/armeabi-v7a/libm.so
new file mode 100644
index 0000000000..ad61d58bd6
Binary files /dev/null and b/ports/iosas/iosas/lib/armeabi-v7a/libm.so differ
diff --git a/ports/iosas/iosas/libs/libcrypto.so.1.1 b/ports/iosas/iosas/libs/libcrypto.so.1.1
new file mode 100644
index 0000000000..faf4d9630e
Binary files /dev/null and b/ports/iosas/iosas/libs/libcrypto.so.1.1 differ
diff --git a/ports/iosas/iosas/libs/libopenal.so.1 b/ports/iosas/iosas/libs/libopenal.so.1
new file mode 100644
index 0000000000..2f3490e64e
Binary files /dev/null and b/ports/iosas/iosas/libs/libopenal.so.1 differ
diff --git a/ports/iosas/iosas/libs/libzip.so.5 b/ports/iosas/iosas/libs/libzip.so.5
new file mode 100644
index 0000000000..6733e333a5
Binary files /dev/null and b/ports/iosas/iosas/libs/libzip.so.5 differ
diff --git a/ports/iosas/iosas/libs/splash b/ports/iosas/iosas/libs/splash
new file mode 100644
index 0000000000..faee12ec05
Binary files /dev/null and b/ports/iosas/iosas/libs/splash differ
diff --git a/ports/iosas/iosas/patching_splash.png b/ports/iosas/iosas/patching_splash.png
new file mode 100644
index 0000000000..4cb87ae4c8
Binary files /dev/null and b/ports/iosas/iosas/patching_splash.png differ
diff --git a/ports/iosas/iosas/pm-config.ini b/ports/iosas/iosas/pm-config.ini
new file mode 100644
index 0000000000..383d494104
--- /dev/null
+++ b/ports/iosas/iosas/pm-config.ini
@@ -0,0 +1,3 @@
+[Performance]
+FrameSkip=20
+IdolSFX=1
\ No newline at end of file
diff --git a/ports/iosas/iosas/splash.png b/ports/iosas/iosas/splash.png
new file mode 100644
index 0000000000..a84421999b
Binary files /dev/null and b/ports/iosas/iosas/splash.png differ
diff --git a/ports/iosas/iosas/tools/gm-Ktool.py b/ports/iosas/iosas/tools/gm-Ktool.py
new file mode 100644
index 0000000000..f0d3c4b7f1
--- /dev/null
+++ b/ports/iosas/iosas/tools/gm-Ktool.py
@@ -0,0 +1,490 @@
+#!/usr/bin/env python3
+
+"""
+ name: K-dog tool
+ description: compress wav data into ogg data in Gamemaker data.win files
+ author: kotzebuedog
+ usage: ./gm-Ktool.py data.win data-k.win -a 0 -m 524288
+ will compress all wav data > 512 KB in audiogroup 0
+ -a and -m are optionnal
+"""
+
+from pathlib import Path
+import os
+from subprocess import Popen, PIPE
+import threading
+
+import argparse
+
+from struct import pack,unpack
+
+MIN_SIZE = 1024*1024 # 1 MB
+
+class IFFdata:
+
+ def __init__(self, fin_path, verbose=0, bitrate=128):
+ self.filein_path = fin_path
+ self.filein = None
+ self.filein_size = 0 # includes FORM (4B) and size (4B)
+ self.fileout_path = None
+ self.fileout = None
+ self.fileout_size = 0 # includes FORM (4B) and size (4B)
+ self.chunk_list = None
+ self.sond = None
+ self.audo = None
+
+ self.verbose = verbose
+ self.bitrate = bitrate
+
+ self.__init_chunk_list()
+ self.__init_sond()
+ self.__init_audo()
+
+ def __vprint(self, msg):
+ if self.verbose > 0:
+ print(msg)
+
+ def __vvprint(self, msg):
+ if self.verbose > 1:
+ print(msg)
+
+ def __vvvprint(self, msg):
+ if self.verbose > 2:
+ print(msg)
+
+ def __pretty_size(self,size):
+
+ units = ['B ','KB','MB','GB']
+
+ n = size
+
+ while n > 1024:
+ n = n / 1024
+ units = units[1:]
+
+ return f"{int(n):#4} {units[0]}"
+
+ def __open_filein(self):
+
+ try:
+ self.filein = open(self.filein_path,'rb')
+ self.filein.seek(0, os.SEEK_END)
+ self.filein_size = self.filein.tell()
+ self.filein.seek(0)
+
+ except (FileNotFoundError, PermissionError, OSError, IOError):
+ self.__vprint("Error opening file")
+ exit(1)
+
+ def __open_fileout(self):
+
+ try:
+ self.fileout = open(self.fileout_path,'wb')
+ self.filout_size = 0
+
+ except (FileNotFoundError, PermissionError, OSError, IOError):
+ self.__vprint("Error opening file")
+ exit(1)
+
+ def __find_next_chunk(self):
+ offset = self.filein.tell()
+ token = self.filein.read(4).decode('ascii')
+ size = unpack('> 6,
+ "isCompressed" : (flags_raw & 0x02) >> 1,
+ "isEmbedeed" : flags_raw & 0x01 }
+
+ sondkey = f"{i:#04}"
+ self.sond[sondkey] = {
+ "name_offset": name_offset,
+ "name" : name,
+ "flags_raw" : flags_raw,
+ "flags" : flags,
+ "type_offset": type_offset,
+ "type" : type,
+ "file_offset": file_offset,
+ "file" : file,
+ "effect" : effect,
+ "volume" : volume,
+ "pitch" : pitch,
+ "audiogroup" : audiogroup,
+ "audiofile" : audiofile,
+ "rebuild" : 0
+ }
+ self.__vvvprint(f"SOND entry {i:#04}: {self.sond[sondkey]}")
+
+
+ def __init_audo(self):
+ self.filein.seek(self.chunk_list["AUDO"]["offset"] + 8)
+ nb_entries = unpack(' 0:
+ padding = alignement - misalignement
+
+ return padding
+
+ def __write_to_file_sond(self):
+ self.filein.seek(self.chunk_list["SOND"]["offset"])
+ size = self.chunk_list["SOND"]["size"]
+ self.__vvprint("Writing SOND")
+
+ if self.chunk_list["SOND"]["rebuild"] == 0:
+ self.__vvprint("Direct copy SOND")
+ self.fileout.write(self.filein.read(size + 8))
+ self.fileout_size += size + 8
+
+ else:
+ self.__vvprint("Rebuild SOND")
+ self.fileout.write(self.filein.read(12)) # Token, size, nb entries should be the same
+ self.fileout_size += 12
+ self.fileout.write(self.filein.read(len(self.sond.keys()) * 4)) # offsets don't change
+ self.fileout_size += len(self.sond.keys()) * 4
+
+ for n, key in enumerate(self.sond.keys()):
+ if self.sond[key]["rebuild"] == 0:
+ self.__vvvprint(f"Direct copy SOND entry {key}")
+ # We copy the entry from the input file
+ self.fileout.write(self.filein.read(36)) # same entry (36B)
+
+ else:
+ self.__vvvprint(f"Rebuild SOND entry {key}")
+ self.filein.seek(36,1) # we jump this chunk on the input file (36B)
+ self.fileout.write(self.__audo_get_raw_entry(key))
+
+ self.fileout_size += 36
+
+ padding = self.__get_padding(16)
+
+ self.fileout.write(b'\x00' * padding )
+ self.fileout_size += padding
+
+ def __write_to_file_audo(self):
+ self.filein.seek(self.chunk_list["AUDO"]["offset"])
+ size = self.chunk_list["AUDO"]["size"]
+ self.__vvprint("Writing AUDO")
+
+ audo_offset = self.fileout.tell()
+
+ if self.chunk_list["AUDO"]["rebuild"] == 0:
+ self.__vvprint("Direct copy AUDO")
+
+ self.fileout.write(self.filein.read(size + 8))
+ self.fileout_size += size + 8
+
+ padding = self.__get_padding(16)
+
+ self.fileout.write(b'\x00' * padding )
+ self.fileout_size += padding
+
+ else:
+ self.__vvprint("Rebuild AUDO")
+ self.fileout.write(self.filein.read(4)) # Token should be the same
+ self.fileout_size += 4
+ self.fileout.write(pack(' 0):
+ process.stdin.write(self.filein.read(remainder_size)) # Write remainder bytes of data bytes to stdin pipe of oggenc sub-process.
+
+ process.stdin.close() # Close stdin pipe - closing stdin finish encoding the data, and closes FFmpeg sub-process.
+
+ def __write_to_file_audo_ogg(self, audo_entry):
+ chunksize = 0
+ oggenc_process = (
+ Popen(["oggenc","-b",f"{self.bitrate}","-"],bufsize=1024,stdin=PIPE, stdout=PIPE, stderr=PIPE )
+ )
+
+ thread = threading.Thread(target=self.__thread_writer, args=(oggenc_process,audo_entry))
+ thread.start()
+
+ while thread.is_alive():
+ ogg_chunk = oggenc_process.stdout.read(1024) # Read chunk with arbitrary size from stdout pipe
+ chunksize += len(ogg_chunk)
+ self.fileout.write(ogg_chunk) # Write the encoded chunk to the "in-memory file".
+
+
+ # Read the last encoded chunk.
+ ogg_chunk = oggenc_process.stdout.read() # Read chunk with arbitrary size from stdout pipe
+ self.fileout.write(ogg_chunk) # Write the encoded chunk to the "in-memory file".
+ chunksize += len(ogg_chunk)
+
+ oggenc_process.wait() # Wait for oggenc sub-process to end
+
+ return chunksize
+
+ def get_sond(self):
+ return self.sond
+
+ def get_audo(self):
+ return self.audo
+
+ def sond_replace_entry(self,n,sondentry):
+ self.sond[n] = sondentry
+
+ def audo_replace_entry(self,n,filein_path):
+ self.audo[n]["data"] = filein_path
+
+ def audo_get_entry(self,n,filein_path):
+ with open(filein_path, 'wb+') as fout:
+ self.filein.seek(self.audo[n]["offset"] + 4)
+ fout.write(self.filein.read(self.audo[n]["size"]))
+
+ def audio_set_compress(self, agrp_list ,minsize):
+
+ updated_entries = 0
+ for _,key in enumerate(self.sond):
+
+ if (self.sond[key]["audiogroup"] in agrp_list or len(agrp_list) == 0) and self.sond[key]["flags"]["isCompressed"] == 0 :
+ audiofile = f"{self.sond[key]['audiofile']:#04}" # it is a file number (eg 0001)
+ size = self.audo[audiofile]["size"]
+
+ if size >= minsize:
+
+ self.sond[key]["flags"]["isCompressed"] = 1
+ self.sond[key]["flags"]["isEmbedded"] = 0
+ self.sond[key]["flags_raw"] = self.sond[key]["flags"]["isRegular"] * 0x64 | \
+ self.sond[key]["flags"]["isCompressed"] * 0x02 | \
+ self.sond[key]["flags"]["isEmbedded"] * 0x01
+
+ # toggle rebuild and compress because we will update data
+ self.sond[key]["rebuild"] = 1
+ self.audo[audiofile]["compress"] = 1
+
+ self.__vprint(f"audo {audiofile} ({self.sond[key]['name']}) with size {self.__pretty_size(size)} will be compressed")
+
+
+ updated_entries += 1
+
+ # if we have updated one or more entries we need to rebuild AUDO and SOND chunks
+ if updated_entries > 0:
+ self.__vprint(f"{updated_entries} wav entrie(s) will be compressed")
+
+ # toggle rebuild because we will update data
+ self.chunk_list["FORM"]["rebuild"] = 1
+ self.chunk_list["SOND"]["rebuild"] = 1
+ self.chunk_list["AUDO"]["rebuild"] = 1
+
+ def write_to_file(self, fout_path):
+ self.fileout_path = fout_path
+ self.__open_fileout()
+
+ if self.chunk_list["FORM"]["rebuild"] == 1:
+
+ for _,token in enumerate(self.chunk_list):
+ if token == "SOND":
+ self.__write_to_file_sond()
+ elif token == "AUDO":
+ self.__write_to_file_audo()
+ else:
+ self.__write_to_file_otherchunk(token)
+
+ self.fileout.seek(4)
+ self.fileout.write(pack('