Skip to content

Commit

Permalink
Merge pull request #217 from K0lb3/K0lb3-patch-1
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
K0lb3 authored Dec 21, 2023
2 parents cc87a54 + 765b84c commit 150ca3b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
2 changes: 1 addition & 1 deletion UnityPy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.10.6"
__version__ = "1.10.7"

from .environment import Environment
from .helpers.ArchiveStorageManager import set_assetbundle_decrypt_key
Expand Down
30 changes: 10 additions & 20 deletions UnityPy/export/AudioClipConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,15 @@ def import_pyfmodex():

# prepare the environment for pyfmodex
if system == "Windows":
# register fmod.dll, so that windll.fmod in pyfmodex can find it
ctypes.WinDLL(os.path.join(LIB_PATH, "fmod.dll"))
import pyfmodex
os.environ["PYFMODEX_DLL_PATH"] = os.path.join(LIB_PATH, "fmod.dll")
else:
# It's a bit more complicated on Linux and Mac
# as CDLL doesn't cache the loaded libraries.
# So our only option is to hook into the ctypes loader
# and add the path to the library there.
CDLL = ctypes.CDLL

def cdll_hook(name, *args, **kwargs):
if name.startswith("libfmod"):
name = os.path.join(LIB_PATH, name)
return CDLL(name, *args, **kwargs)

ctypes.CDLL = cdll_hook
import pyfmodex

ctypes.CDLL = CDLL
ext = "dylib" if system == "Darwin" else "so"
os.environ["PYFMODEX_DLL_PATH"] = os.path.join(LIB_PATH, f"libfmod.{ext}")

# hotfix ctypes for pyfmodex for non windows
ctypes.windll = getattr(ctypes, "windll", None)

import pyfmodex


def extract_audioclip_samples(audio) -> dict:
Expand Down Expand Up @@ -109,7 +99,7 @@ def dump_samples(clip):
sound = system.create_sound(
bytes(clip.m_AudioData),
pyfmodex.flags.MODE.OPENMEMORY,
exinfo=pyfmodex.system.CREATESOUNDEXINFO(
exinfo=pyfmodex.structure_declarations.CREATESOUNDEXINFO(
length=clip.m_Size,
numchannels=clip.m_Channels,
defaultfrequency=clip.m_Frequency,
Expand All @@ -134,7 +124,7 @@ def dump_samples(clip):

def subsound_to_wav(subsound):
# get sound settings
length = subsound.get_length(0x00000004) # TIMEUNIT.PCMBYTES
length = subsound.get_length(pyfmodex.enums.TIMEUNIT.PCMBYTES)
channels = subsound.format.channels
bits = subsound.format.bits
sample_rate = int(subsound.default_frequency)
Expand Down
2 changes: 1 addition & 1 deletion UnityPy/files/SerializedFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def set_version(self, string_version):
build_type = re.findall(r"([^\d.])", string_version)
self.build_type = BuildType(build_type[0] if build_type else "")
version_split = re.split(r"\D", string_version)
self.version = tuple(int(x) for x in version_split)
self.version = tuple(int(x) for x in version_split[:4])

def read_type_tree(self):
type_tree = []
Expand Down
2 changes: 1 addition & 1 deletion UnityPy/helpers/Tpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def fromString(version: str) -> UnityVersion:
return UnityVersion(version.split("."))

@staticmethod
def fromList(major: int, minor: int, patch: int, build: int) -> UnityVersion:
def fromList(major: int = 0, minor: int = 0, patch: int = 0, build: int = 0) -> UnityVersion:
return UnityVersion(major << 48 | minor << 32 | patch << 16 | build)

@property
Expand Down
2 changes: 1 addition & 1 deletion UnityPy/streams/EndianBinaryReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Union
from io import BytesIO, BufferedIOBase, IOBase, BufferedReader

reNot0 = re.compile(b"(.*?)\x00")
reNot0 = re.compile(b"(.*?)\x00", re.S)

SYS_ENDIAN = "<" if sys.byteorder == "little" else ">"

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
# raw typetree dumping
"tabulate",
# audio extraction
"pyfmodex",
"pyfmodex >= 0.7.1",
# filesystem handling
"fsspec",
]
Expand Down

0 comments on commit 150ca3b

Please sign in to comment.