diff --git a/.gitignore b/.gitignore index 77626f5..c02d2f8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ noesis*/ log.txt config.ini build_final/ +*.log diff --git a/README.md b/README.md index fa57bea..6f5bf2a 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ To use script with Noesis, please follow below steps: # Badges ![GitHub](https://img.shields.io/github/license/bartlomiejduda/EA-Graphics-Manager?style=plastic) +[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) ![GitHub repo size](https://img.shields.io/github/repo-size/bartlomiejduda/EA-Graphics-Manager?style=plastic) ![GitHub all releases](https://img.shields.io/github/downloads/bartlomiejduda/EA-Graphics-Manager/total) ![GitHub last commit](https://img.shields.io/github/last-commit/bartlomiejduda/EA-Graphics-Manager?style=plastic) diff --git a/src/EA_Image/ea_image_main.py b/src/EA_Image/ea_image_main.py index c62e321..656e997 100644 --- a/src/EA_Image/ea_image_main.py +++ b/src/EA_Image/ea_image_main.py @@ -7,6 +7,7 @@ import os import struct +import traceback from reversebox.common.logger import get_logger from reversebox.compression.compression_refpack import RefpackHandler @@ -150,7 +151,7 @@ def _set_little_endianess(): self.f_dir_endianess = "<" # little # set endianess for the rest of the file - if self.sign in ("SHPG", "SHPM", "ShpG", "ShpM"): + if self.sign in ("SHPG", "ShpG", "ShpM"): _set_big_endianess() else: _set_little_endianess() @@ -380,25 +381,35 @@ def _is_image_swizzled() -> bool: # unswizzling logic if _is_image_swizzled(): - if self.sign in ("SHPX", "ShpX", "SHPI", "ShpF"): # for XBOX and PC games - image_data = unswizzle_morton( - image_data, ea_dir_entry.h_width, ea_dir_entry.h_height, get_bpp_for_image_type(entry_type) - ) - elif self.sign in ("SHPM", "ShpM"): # for PSP games - image_data = unswizzle_psp( - image_data, ea_dir_entry.h_width, ea_dir_entry.h_height, get_bpp_for_image_type(entry_type) - ) - elif self.sign in ("SHPS", "ShpS") and (entry_type < 8 or entry_type > 15): # for PS2 games - if get_bpp_for_image_type(entry_type) == 4: - image_data = unswizzle_ps2_4bit(image_data, ea_dir_entry.h_width, ea_dir_entry.h_height) - elif get_bpp_for_image_type(entry_type) == 8: - image_data = unswizzle_ps2_8bit(image_data, ea_dir_entry.h_width, ea_dir_entry.h_height) - elif self.sign in ("SHPG", "ShpG"): # for WII/GameCube games - image_data = unswizzle_gamecube( - image_data, ea_dir_entry.h_width, ea_dir_entry.h_height, get_bpp_for_image_type(entry_type) - ) - else: - logger.warning(f"Swizzling for signature {self.sign} is not supported yet!") + try: + if self.sign in ("SHPX", "ShpX", "SHPI", "ShpF"): # for XBOX and PC games + image_data = unswizzle_morton( + image_data, ea_dir_entry.h_width, ea_dir_entry.h_height, get_bpp_for_image_type(entry_type) + ) + elif self.sign in ("SHPM", "ShpM"): # for PSP games + image_data = unswizzle_psp( + image_data, ea_dir_entry.h_width, ea_dir_entry.h_height, get_bpp_for_image_type(entry_type) + ) + elif self.sign in ("SHPS", "ShpS") and ( + entry_type < 8 or entry_type > 15 + ): # for PS2 games (standard textures) + if get_bpp_for_image_type(entry_type) == 4: + image_data = unswizzle_ps2_4bit(image_data, ea_dir_entry.h_width, ea_dir_entry.h_height) + elif get_bpp_for_image_type(entry_type) == 8: + image_data = unswizzle_ps2_8bit(image_data, ea_dir_entry.h_width, ea_dir_entry.h_height) + elif ( + self.sign in ("SHPS", "ShpS") and entry_type >= 8 and entry_type <= 15 + ): # for PS2 games (GST textures) + pass # swizzling handled by decoder + elif self.sign in ("SHPG", "ShpG"): # for WII/GameCube games + image_data = unswizzle_gamecube( + image_data, ea_dir_entry.h_width, ea_dir_entry.h_height, get_bpp_for_image_type(entry_type) + ) + else: + logger.warning(f"Swizzling for signature {self.sign} is not supported yet!") + except Exception as error: + logger.error(f"Error while unswizzling images! Error: {error}") + logger.error(traceback.format_exc()) # decoding logic if entry_type == 1: diff --git a/src/main.py b/src/main.py index 69cea5a..cb3d50a 100644 --- a/src/main.py +++ b/src/main.py @@ -15,7 +15,7 @@ from src.GUI.GUI_main import EAManGui -VERSION_NUM = "v0.21.2" +VERSION_NUM = "v0.21.3" logger = get_logger("main")