-
-
Notifications
You must be signed in to change notification settings - Fork 161
Improve config and files module #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf48db5
fix: better type hint in EndianBinaryReader/Writer
isHarryh 8f7c557
refactor(files): use assertion for version-specific assignment
isHarryh f3bf912
chore(files): fix typo and remove legacy code
isHarryh da1a5ac
fix(files): overall type hint corrections
isHarryh d848ab2
fix(files): use generic type in EndianBinaryWriter
isHarryh fd77d1f
feat(config): unset default fallback version
isHarryh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,41 @@ | ||
| # used when no version is defined by the SerializedFile or its BundleFile | ||
| FALLBACK_UNITY_VERSION = "2.5.0f5" | ||
| # determines if the typetree structures for the Object types will be parsed | ||
| # disabling this will reduce the load time by a lot (half of the time is spend on parsing the typetrees) | ||
| # but it will also prevent saving an edited file | ||
| import warnings | ||
|
|
||
| from .exceptions import UnityVersionFallbackError, UnityVersionFallbackWarning | ||
|
|
||
|
|
||
| FALLBACK_UNITY_VERSION = None | ||
| """The Unity version to use when no version is defined | ||
| by the SerializedFile or its BundleFile. | ||
|
|
||
| You may manually configure this value to a version string, e.g. `2.5.0f5`. | ||
| """ | ||
|
|
||
| SERIALIZED_FILE_PARSE_TYPETREE = True | ||
| """Determines if the typetree structures for the Object types will be parsed. | ||
|
|
||
| # GLOBAL WARNING SUPPRESSION | ||
| FALLBACK_VERSION_WARNED = False # for FALLBACK_UNITY_VERSION | ||
| Disabling this will reduce the load time by a lot (half of the time is spend on parsing the typetrees), | ||
| but it will also prevent saving an edited file. | ||
| """ | ||
|
|
||
|
|
||
| # WARNINGS CONTROL | ||
| warnings.simplefilter("once", UnityVersionFallbackWarning) | ||
|
|
||
|
|
||
| # GET FUNCTIONS | ||
| def get_fallback_version(): | ||
| global FALLBACK_VERSION_WARNED | ||
| if not FALLBACK_VERSION_WARNED: | ||
| print( | ||
| f"Warning: 0.0.0 version found, defaulting to UnityPy.config.FALLBACK_UNITY_VERSION ({FALLBACK_UNITY_VERSION})" # noqa: E501 | ||
| global FALLBACK_UNITY_VERSION | ||
|
|
||
| if not isinstance(FALLBACK_UNITY_VERSION, str): | ||
| raise UnityVersionFallbackError( | ||
| "No valid Unity version found, and the fallback version is not correctly configured. " | ||
| + "Please explicitly set the value of UnityPy.config.FALLBACK_UNITY_VERSION." | ||
| ) | ||
| FALLBACK_VERSION_WARNED = True | ||
|
|
||
| warnings.warn( | ||
| f"No valid Unity version found, defaulting to UnityPy.config.FALLBACK_UNITY_VERSION ({FALLBACK_UNITY_VERSION})", # noqa: E501 | ||
| category=UnityVersionFallbackWarning, | ||
| stacklevel=2 | ||
| ) | ||
|
|
||
| return FALLBACK_UNITY_VERSION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,14 @@ | ||
| class TypeTreeError(Exception): | ||
| def __init__(self, message, nodes): | ||
| # Call the base class constructor with the parameters it needs | ||
| def __init__(self, message, nodes): | ||
| super().__init__(message) | ||
| self.nodes = nodes | ||
|
|
||
|
|
||
| class UnityVersionFallbackError(Exception): | ||
| def __init__(self, message): | ||
| super().__init__(message) | ||
|
|
||
|
|
||
| class UnityVersionFallbackWarning(UserWarning): | ||
| def __init__(self, message): | ||
| super().__init__(message) | ||
| self.nodes = nodes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.