Skip to content

Conversation

@isHarryh
Copy link
Contributor

@isHarryh isHarryh commented Jun 1, 2025

Summary

This PR does some minor changes to Texture2DConverter.

  • platform_blob can be List[int] in newer version of Unity, instead of only bytes.
  • One platform_blob type hint still uses bytes, now corrected to List[int].
  • if TYPE_CHECKING: assert xxx is not None seems redundant, now removed if.
  • Pre-converts platform to BuildTarget enum.
  • Wraps swizzle texture_format conversion into TextureSwizzler.
  • Simplifies the redundant if-statements in image_to_texture2d.
  • Optimizes docstrings and typos.

Along with two typo fixes in the pyproject.toml:

  • Fixes the invalid license field in pyproject.toml which causes CodeQL failing.
  • Fixes the typo of the keyword data-minig in pyproject.toml.

@isHarryh isHarryh force-pushed the patch-texture-type branch from 6660d27 to 3517281 Compare June 6, 2025 02:02
Copy link
Owner

@K0lb3 K0lb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry that I'm only replying now.

I will be blunt, I don't really see the point of this PR.

The typo fixes, doc string adjustments and the BC format collapsing are okay, but that's it.

TextureSwizzler.get_corrected_texture_format is basically a one-time use function,
which only adds a layer of indirection without any benefit, as at one of the two places where it's being used, the same check has to be done again anyway.

TextureSwizzler.PlatformBlobType is also not really useful.
The usage of bytes from before was actually wrong, as the platformblob type is defined by the Texture2D field of it, so just List[int] is enough.

The platform type also doesn't have to be narrowed down to BuildTarget,
as the only use of platform is in an equality check, which works just fine with an int as well.

@isHarryh isHarryh force-pushed the patch-texture-type branch from 3517281 to 9178ed7 Compare June 6, 2025 09:58
@isHarryh
Copy link
Contributor Author

isHarryh commented Jun 6, 2025

Apologies - I didn’t fully considered the current needs, so I’ve decided to go ahead and revert the 3 changes you mentioned, to narrow the PR to only typo fixes.

My initial intention with these changes was to centralize the logic and make the code more readable in the long run. But I understand that, the added abstraction doesn’t bring enough value and instead introduces unnecessary complexity.

Thanks again for your constructive feedback - it’s much appreciated.

@isHarryh
Copy link
Contributor Author

isHarryh commented Jun 6, 2025

This PR now contains:

  1. Typo and docstring adjustments.
  2. BC format if-statements collapsing.

with some new changes:

  1. One platform_blob type hint still uses bytes, now corrected to List[int].
  2. if TYPE_CHECKING: assert xxx is not None seems redundant, now removed if.
  3. Fixes the invalid license field in pyproject.toml which causes CodeQL failing.
  4. Fixes the typo of the keyword data-minig in pyproject.toml.

@isHarryh isHarryh changed the title Refactor swizzle process and cleanup Texture2DConverter Cleanup Texture2DConverter and fix typos in pyproject.toml Jun 6, 2025
@isHarryh isHarryh requested a review from K0lb3 June 6, 2025 10:14
pyproject.toml Outdated
description = "A Unity extraction and patching package"
readme = "README.md"
license = "MIT"
license = { text = "MIT" }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly writing a SPDX license expression is the new expected value for the license field, see Writing your pyproject.toml - Python Packaging User Guide.

Copy link
Contributor Author

@isHarryh isHarryh Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, PEP 639 adopted SPDX format, and toml-table based format is deprecating. But sadly for Python<=3.8/setuptools<=v75.3.2 , build will fail.

I have reverted this line of change, and you can decide how to deal with it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying that.
I guess that I will simply have to set the min version to 3.9.

3.7 is already broken due to typing_extensions used in some dependency, so might as well remove 3.8 support as well.
As there are already breaking commits up, this can come with the next minor update.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As indicated in that issue, I will simply drop the commit that changed the version, while adding a new one for the setuptools max version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo, we might consider delaying the restriction on the maximum version of setuptools, as some projects that currently rely on the latest version of setuptools may encounter dependency resolution errors.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will simply set to to a possible future version, going by the current release cadence for now, as I would probably forget about it otherwise.

You have a pretty good point there that I didn't even think about.
This makes the whole issue very tricky.

I prefer to support old versions as long as it doesn't take too much effort to support them,
and there are certainly options to work around the issue, just that they are a bit too hacky imo.

@K0lb3
Copy link
Owner

K0lb3 commented Jun 7, 2025

Thanks for the changes and the effort.
I will re-check your PR at Monday, but so far it looks fine now.

My handling of OOP and abstraction in UnityPy, and well, overall, is probably pretty non-standard, and might appear a bit arbitrary, which I'm sorry for.
Imo code should be directly readable without having to follow dozens of deep trails through "useless" OOP patterns to understand what's going on exactly.
So, based on that, I think that only either very long condition specific code, "tricky" code, or often re-used code should be "extracted" from the source where it actually gets used.
Ofc everyone has a different take on what's readable, to say nothing about my vague own conditions, but well, being able to decide that for a project is one of the advantages of owning it in exchange for maintaining it.

Anyway,
regarding the long term, I plan to make UnityPy more modular, moving all the exporters and most helpers into separate projects.
UnityPy itself will then only handle the Unity asset parsing and saving, as well as the object loading and saving.
The processing of the objects will then be in the hands of "other" projects, which I plan to name "exchange", so export and import.
That's also the reason the classes/legacy_patch is named the way it is.

K0lb3
K0lb3 previously approved these changes Jun 14, 2025
@K0lb3 K0lb3 force-pushed the patch-texture-type branch from 75cd5ba to f74797f Compare June 14, 2025 19:50
@K0lb3 K0lb3 merged commit 4f07bc7 into K0lb3:master Jun 14, 2025
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants