Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion Klib/GMblob.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def _get_padding(self, alignement = 16):
padding = alignement - misalignement

return padding

return self.get_str(name_str_offset)

def _write_to_file_otherchunk(self,token):
self.filein.seek(self.chunk_list[token]["offset"])
Expand Down Expand Up @@ -446,6 +448,32 @@ def get_str(self, str_offset):
size = unpack('<I', self.filein.read(4))[0]

return self.filein.read(size).decode('utf-8')

def __get_audiogroup_filename(self, audiogroup_id):
# The AGRP chunk starts with 4 bytes for entry count, then a table of offsets
self.filein.seek(self.chunk_list["AGRP"]["offset"] + 8)
nb_entries = unpack('<I', self.filein.read(4))[0]

if audiogroup_id >= nb_entries:
return None

# Jump to the offset of the specific audiogroup entry
# AGRP Chunk: [4B Count] [4B Offset0] [4B Offset1] ...
self.filein.seek(self.chunk_list["AGRP"]["offset"] + 12 + (audiogroup_id * 4))
entry_offset = unpack('<I', self.filein.read(4))[0]

# Seek to the entry
self.filein.seek(entry_offset)

# In newer GM versions, the name offset might be at a different position
# or followed by different flags. We try to read the string offset.
name_str_offset = unpack('<I', self.filein.read(4))[0]

# Validation: If the offset is 0 or outside the file, the chunk structure might be shifted
if name_str_offset == 0 or name_str_offset > self.filein_size:
return None

return self.get_str(name_str_offset)

def __init_sond(self):
self.filein.seek(self.chunk_list["SOND"]["offset"] + 8)
Expand Down Expand Up @@ -512,7 +540,35 @@ def __init_sond(self):

def __init_audiogroup_dat(self, audiogroup):
if audiogroup > 0 and not f"{audiogroup}" in self.audiogroup_dat.keys():
self.audiogroup_dat[f"{audiogroup}"] = GMaudiogroup(self.filein_path.parents[0] / f"audiogroup{audiogroup}.dat" , self.verbose, self.audiosettings, audiogroup)
# 1. Get the internal friendly name
ag_name = self.__get_audiogroup_filename(audiogroup)
base_path = self.filein_path.parents[0]

# Define potential filenames
potential_names = [
ag_name, # Friendly name (e.g., Aud_SFX_Weapons)
f"{ag_name}.dat", # Friendly name + .dat
f"audiogroup{audiogroup}.dat" # Indexed name (e.g., audiogroup1.dat)
]

ag_path = None
for name in potential_names:
test_path = base_path / name
if test_path.exists():
ag_path = test_path
break

if ag_path:
self._vprint(f"[AGRP {audiogroup}] Found asset file: {ag_path.name}")
self.audiogroup_dat[f"{audiogroup}"] = GMaudiogroup(
ag_path,
self.verbose,
self.audiosettings,
audiogroup
)
else:
self._vprint(f"Warning: Could not find audio file for group '{ag_name}' "
f"(Tried: {', '.join(potential_names)})")

def __sond_get_raw_entry(self,key):

Expand Down