|
3 | 3 | import ctypes |
4 | 4 | import os |
5 | 5 | import platform |
6 | | -import sys |
7 | | -from importlib.resources import path |
8 | | -from typing import TYPE_CHECKING, Dict |
| 6 | +from typing import TYPE_CHECKING, Dict, Union |
9 | 7 |
|
10 | 8 | from UnityPy.streams import EndianBinaryWriter |
11 | 9 |
|
|
22 | 20 | pyfmodex = None |
23 | 21 |
|
24 | 22 |
|
| 23 | +def get_fmod_path( |
| 24 | + system: Union["Windows", "Linux", "Darwin"], arch: ["x64", "x86", "arm"] |
| 25 | +) -> str: |
| 26 | + if system == "Darwin": |
| 27 | + # universal dylib |
| 28 | + return "lib/FMOD/Darwin/libfmod.dylib" |
| 29 | + |
| 30 | + if system == "Windows": |
| 31 | + return f"lib/FMOD/Windows/{arch}/fmod.dll" |
| 32 | + |
| 33 | + if system == "Linux": |
| 34 | + if arch == "x64": |
| 35 | + arch = "x86_64" |
| 36 | + return f"lib/FMOD/Linux/{arch}/libfmod.so" |
| 37 | + |
| 38 | + raise NotImplementedError(f"Unsupported system: {system}") |
| 39 | + |
| 40 | + |
25 | 41 | def import_pyfmodex(): |
26 | 42 | global pyfmodex |
27 | 43 | if pyfmodex is not None: |
28 | 44 | return |
29 | 45 |
|
30 | 46 | # determine system - Windows, Darwin, Linux, Android |
31 | 47 | system = platform.system() |
32 | | - if system == "Linux" and "ANDROID_BOOTLOGO" in os.environ: |
33 | | - system = "Android" |
34 | | - # determine architecture |
35 | | - machine = platform.machine() |
36 | 48 | arch = platform.architecture()[0] |
| 49 | + machine = platform.machine() |
37 | 50 |
|
38 | | - if system in ["Windows", "Darwin"]: |
39 | | - if arch == "32bit": |
40 | | - arch = "x86" |
41 | | - elif arch == "64bit": |
42 | | - arch = "x64" |
43 | | - elif system == "Linux": |
44 | | - # Raspberry Pi and Linux on arm projects |
45 | | - if "arm" in machine: |
46 | | - if arch == "32bit": |
47 | | - arch = "armhf" if machine.endswith("l") else "arm" |
48 | | - elif arch == "64bit": |
49 | | - # Raise an exception for now; Once it gets supported by FMOD we can just modify the code here |
50 | | - pyfmodex = False |
51 | | - raise NotImplementedError( |
52 | | - "ARM64 not supported by FMOD.\nUse a 32bit python version." |
53 | | - ) |
54 | | - elif arch == "32bit": |
55 | | - arch = "x86" |
56 | | - elif arch == "64bit": |
57 | | - arch = "x86_64" |
58 | | - else: |
59 | | - pyfmodex = False |
60 | | - raise NotImplementedError( |
61 | | - "Couldn't find a correct FMOD library for your system ({system} - {arch})." |
62 | | - ) |
| 51 | + if "arm" in machine or "aarch64" in machine: |
| 52 | + arch = "arm" |
| 53 | + elif arch == "32bit": |
| 54 | + arch = "x86" |
| 55 | + elif arch == "64bit": |
| 56 | + arch = "x64" |
| 57 | + |
| 58 | + fmod_rel_path = get_fmod_path(system, arch) |
| 59 | + fmod_path = os.path.join( |
| 60 | + os.path.dirname(os.path.dirname(os.path.realpath(__file__))), fmod_rel_path |
| 61 | + ) |
| 62 | + os.environ["PYFMODEX_DLL_PATH"] = fmod_path |
63 | 63 |
|
64 | 64 | # build path and load library |
65 | 65 | # prepare the environment for pyfmodex |
66 | | - if system == "Windows": |
67 | | - libname = "fmod.dll" |
68 | | - else: |
69 | | - ext = "dylib" if system == "Darwin" else "so" |
70 | | - libname = f"libfmod.{ext}" |
| 66 | + if system != "Windows": |
71 | 67 | # hotfix ctypes for pyfmodex for non windows systems |
72 | 68 | ctypes.windll = None |
73 | 69 |
|
74 | | - lib_path = os.path.join( |
75 | | - os.path.dirname(os.path.dirname(os.path.realpath(__file__))), |
76 | | - "lib", |
77 | | - "FMOD", |
78 | | - system, |
79 | | - arch, |
80 | | - libname |
81 | | - ) |
82 | | - os.environ["PYFMODEX_DLL_PATH"] = lib_path |
83 | | - |
84 | 70 | import pyfmodex |
85 | 71 |
|
86 | 72 |
|
|
0 commit comments