1
0
mirror of https://github.com/DarklightGames/io_scene_psk_psa.git synced 2024-11-24 06:50:13 +01:00

Fixed a bug where the importer would crash when importing PSA files from programs using CUE4Parse (#46)

This is not actually a bug in this addon, but a bug with the CUE4Parse library itself. A fix for the library has been submitted (https://github.com/FabianFG/CUE4Parse/issues/103), but there will still be bugged versions hanging around for a while, so it's prudent to have this addon accomodate the broken files, especially since the fix is relatively easy and won't interfere with properly formatted files.

At some point, this fix will be deprecated to reduce cruft.
This commit is contained in:
Colin Basnett 2023-09-09 18:24:38 -07:00
parent 3d460a15e3
commit f185ffbe16
2 changed files with 24 additions and 4 deletions

View File

@ -175,8 +175,9 @@ class PSA_OT_import(Operator, ImportHelper):
if len(result.warnings) > 0:
message = f'Imported {len(sequence_names)} action(s) with {len(result.warnings)} warning(s)\n'
message += '\n'.join(result.warnings)
self.report({'WARNING'}, message)
for warning in result.warnings:
self.report({'WARNING'}, warning)
else:
self.report({'INFO'}, f'Imported {len(sequence_names)} action(s)')

View File

@ -5,6 +5,24 @@ import numpy as np
from .data import *
def _try_fix_cue4parse_issue_103(sequences) -> bool:
# Detect if the file was exported from CUE4Parse prior to the fix for issue #103.
# https://github.com/FabianFG/CUE4Parse/issues/103
# The issue was that the frame_start_index was not being set correctly, and was always being set to the same value
# as the frame_count.
# This fix will eventually be deprecated as it is only necessary for files exported prior to the fix.
if len(sequences) > 0:
if sequences[0].frame_start_index == sequences[0].frame_count:
# Manually set the frame_start_index for each sequence. This assumes that the sequences are in order with
# no shared frames between sequences (all exporters that I know of do this, so it's a safe assumption).
frame_start_index = 0
for i, sequence in enumerate(sequences):
sequence.frame_start_index = frame_start_index
frame_start_index += sequence.frame_count
return True
return False
class PsaReader(object):
"""
This class reads the sequences and bone information immediately upon instantiation and holds onto a file handle.
@ -86,14 +104,15 @@ class PsaReader(object):
elif section.name == b'ANIMINFO':
sequences = []
PsaReader._read_types(fp, Psa.Sequence, section, sequences)
# Try to fix CUE4Parse bug, if necessary.
_try_fix_cue4parse_issue_103(sequences)
for sequence in sequences:
psa.sequences[sequence.name.decode()] = sequence
elif section.name == b'ANIMKEYS':
# Skip keys on this pass. We will keep this file open and read from it as needed.
self.keys_data_offset = fp.tell()
fp.seek(section.data_size * section.data_count, 1)
elif section.name == b'SCALEKEYS':
fp.seek(section.data_size * section.data_count, 1)
else:
raise RuntimeError(f'Unrecognized section "{section.name}"')
fp.seek(section.data_size * section.data_count, 1)
print(f'Unrecognized section in PSA: "{section.name}"')
return psa