|
1 | | -# used when no version is defined by the SerializedFile or its BundleFile |
2 | | -FALLBACK_UNITY_VERSION = "2.5.0f5" |
3 | | -# determines if the typetree structures for the Object types will be parsed |
4 | | -# disabling this will reduce the load time by a lot (half of the time is spend on parsing the typetrees) |
5 | | -# but it will also prevent saving an edited file |
| 1 | +import warnings |
| 2 | + |
| 3 | +from .exceptions import UnityVersionFallbackError, UnityVersionFallbackWarning |
| 4 | + |
| 5 | + |
| 6 | +FALLBACK_UNITY_VERSION = None |
| 7 | +"""The Unity version to use when no version is defined |
| 8 | + by the SerializedFile or its BundleFile. |
| 9 | +
|
| 10 | + You may manually configure this value to a version string, e.g. `2.5.0f5`. |
| 11 | +""" |
| 12 | + |
6 | 13 | SERIALIZED_FILE_PARSE_TYPETREE = True |
| 14 | +"""Determines if the typetree structures for the Object types will be parsed. |
7 | 15 |
|
8 | | -# GLOBAL WARNING SUPPRESSION |
9 | | -FALLBACK_VERSION_WARNED = False # for FALLBACK_UNITY_VERSION |
| 16 | + Disabling this will reduce the load time by a lot (half of the time is spend on parsing the typetrees), |
| 17 | + but it will also prevent saving an edited file. |
| 18 | +""" |
| 19 | + |
| 20 | + |
| 21 | +# WARNINGS CONTROL |
| 22 | +warnings.simplefilter("once", UnityVersionFallbackWarning) |
10 | 23 |
|
11 | 24 |
|
12 | 25 | # GET FUNCTIONS |
13 | 26 | def get_fallback_version(): |
14 | | - global FALLBACK_VERSION_WARNED |
15 | | - if not FALLBACK_VERSION_WARNED: |
16 | | - print( |
17 | | - f"Warning: 0.0.0 version found, defaulting to UnityPy.config.FALLBACK_UNITY_VERSION ({FALLBACK_UNITY_VERSION})" # noqa: E501 |
| 27 | + global FALLBACK_UNITY_VERSION |
| 28 | + |
| 29 | + if not isinstance(FALLBACK_UNITY_VERSION, str): |
| 30 | + raise UnityVersionFallbackError( |
| 31 | + "No valid Unity version found, and the fallback version is not correctly configured. " |
| 32 | + + "Please explicitly set the value of UnityPy.config.FALLBACK_UNITY_VERSION." |
18 | 33 | ) |
19 | | - FALLBACK_VERSION_WARNED = True |
| 34 | + |
| 35 | + warnings.warn( |
| 36 | + f"No valid Unity version found, defaulting to UnityPy.config.FALLBACK_UNITY_VERSION ({FALLBACK_UNITY_VERSION})", # noqa: E501 |
| 37 | + category=UnityVersionFallbackWarning, |
| 38 | + stacklevel=2 |
| 39 | + ) |
| 40 | + |
20 | 41 | return FALLBACK_UNITY_VERSION |
0 commit comments