some other stuff

This commit is contained in:
iAmAsval
2020-11-21 21:54:30 +01:00
parent ded4c7a749
commit 7c9b820a8d
19 changed files with 70 additions and 78 deletions

View File

@@ -62,7 +62,7 @@ namespace FModel
{
string errorMessage = string.Format(FModel.Properties.Resources.UnhandledExceptionOccured, e.Exception.Message);
DebugHelper.WriteException(e.Exception, "thrown in App.xaml.cs by OnDispatcherUnhandledException");
DarkMessageBoxHelper.Show(errorMessage, FModel.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
DarkMessageBoxHelper.Show(errorMessage, FModel.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error, true);
e.Handled = true;
}

View File

@@ -11,12 +11,15 @@ namespace FModel.Creator.Rarities
{
public static void GetRarity(BaseIcon icon, ObjectProperty o)
{
Package p = Utils.GetPropertyPakPackage(o.Value.Resource.OuterIndex.Resource.ObjectName.String);
if (p.HasExport() && !p.Equals(default))
if (o.Value.Resource != null)
{
var obj = p.GetExport<UObject>();
if (obj != null)
GetRarity(icon, obj);
Package p = Utils.GetPropertyPakPackage(o.Value.Resource.OuterIndex.Resource.ObjectName.String);
if (p.HasExport() && !p.Equals(default))
{
var obj = p.GetExport<UObject>();
if (obj != null)
GetRarity(icon, obj);
}
}
}

View File

@@ -625,7 +625,7 @@
<StatusBarItem Grid.Column="0">
<TextBlock x:Name="FModelVersion_TxtBlck" Text="FModel "/>
</StatusBarItem>
<StatusBarItem Grid.Column="1" HorizontalContentAlignment="Center" Height="Auto">
<StatusBarItem Grid.Column="1" HorizontalContentAlignment="Center" Height="Auto" MaxHeight="50">
<TextBlock x:Name="ProcessEvents_TxtBlck" Text="{Binding Pevent, Mode=TwoWay}" Height="Auto"/>
</StatusBarItem>
<StatusBarItem Grid.Column="2" HorizontalContentAlignment="Right">

View File

@@ -6,7 +6,6 @@ namespace FModel.PakReader.IO
public struct FFileIoStoreContainerFile
{
public Stream FileHandle;
public string FileName;
public long CompressionBlockSize;
public string[] CompressionMethods;
public FIoStoreTocCompressedBlockEntry[] CompressionBlocks;

View File

@@ -31,7 +31,7 @@ namespace FModel.PakReader.IO
{
if (!HasDirectoryIndex) return;
if (value != null && !TestAesKey(value)) //if value not null, test but fail, throw not working
throw new ArgumentException(string.Format(FModel.Properties.Resources.AesNotWorking, value.ToStringKey(), ContainerFile.FileName));
throw new ArgumentException(string.Format(FModel.Properties.Resources.AesNotWorking, value.ToStringKey(), FileName));
_aesKey = value; // else, even if value is null, set it
// setting _aesKey to null will disable the corresponding menu item
}
@@ -176,9 +176,9 @@ namespace FModel.PakReader.IO
var remainingSize = dst.Length;
var dstOffset = 0;
for (int blockIndex = firstBlockIndex; blockIndex <= lastBlockIndex; blockIndex++)
for (int i = firstBlockIndex; i <= lastBlockIndex; i++)
{
var compressionBlock = tocResource.CompressionBlocks[blockIndex];
var compressionBlock = tocResource.CompressionBlocks[i];
var rawSize = BinaryHelper.Align(compressionBlock.CompressedSize, AESDecryptor.ALIGN);
var compressedBuffer = new byte[rawSize];

View File

@@ -8,17 +8,15 @@ namespace FModel.PakReader.IO
{
public class IoPackage : Package
{
private byte[] UAsset;
private byte[] UBulk;
private FIoStoreEntry _entry;
private readonly byte[] UAsset;
private readonly byte[] UBulk;
private IoPackageReader _reader;
private string _jsonData = null;
private readonly string _jsonData = null;
internal IoPackage(byte[] asset, byte[] bulk, FIoStoreEntry entry)
internal IoPackage(byte[] asset, byte[] bulk)
{
UAsset = asset;
UBulk = bulk;
_entry = entry;
}
public IoPackageReader Reader
@@ -33,7 +31,7 @@ namespace FModel.PakReader.IO
if (bulk != null)
bulk.Position = 0;
return _reader = new IoPackageReader(asset, bulk, Globals.GlobalData, _entry.ioStore, true);
return _reader = new IoPackageReader(asset, bulk, Globals.GlobalData, true);
}
return _reader;

View File

@@ -8,6 +8,7 @@ namespace FModel.PakReader
static readonly FGuid Magic = new FGuid(0xA14CEE4F, 0x83554868, 0xBD464C6C, 0x7C50DA70);
public readonly string NativeCulture;
public readonly string NativeLocRes;
public readonly string[] CompiledCultures;
public LocMetaReader(Stream stream) : this(new BinaryReader(stream)) { }
@@ -19,22 +20,29 @@ namespace FModel.PakReader
}
var VersionNumber = (Version)reader.ReadByte();
if (VersionNumber > Version.LATEST)
if (VersionNumber > Version.Latest)
{
throw new IOException($"LocMeta file is too new to be loaded! (File Version: {(byte)VersionNumber}, Loader Version: {(byte)Version.LATEST})");
throw new IOException($"LocMeta file is too new to be loaded! (File Version: {(byte)VersionNumber}, Loader Version: {(byte)Version.Latest})");
}
NativeCulture = reader.ReadFString();
NativeLocRes = reader.ReadFString();
if (VersionNumber >= Version.AddedCompiledCultures)
{
CompiledCultures = reader.ReadTArray(() => reader.ReadFString());
}
}
public enum Version : byte
{
/** Initial format. */
INITIAL = 0,
Initial = 0,
/** Added complete list of cultures compiled for the localization target. */
AddedCompiledCultures,
LATEST_PLUS_ONE,
LATEST = LATEST_PLUS_ONE - 1
LatestPlusOne,
Latest = LatestPlusOne - 1
}
}
}

View File

@@ -29,7 +29,7 @@ namespace FModel.PakReader
if (VersionNumber > Version.Latest)
{
throw new IOException($"LocRes file is too new to be loaded! (File Version: {(byte)VersionNumber}, Loader Version: {(byte)LocMetaReader.Version.LATEST})");
throw new IOException($"LocRes file is too new to be loaded! (File Version: {(byte)VersionNumber}, Loader Version: {(byte)LocMetaReader.Version.Latest})");
}
// Read the localized string array

View File

@@ -1,7 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using FModel.Logger;
using FModel.PakReader.IO;
using FModel.PakReader.Parsers.Objects;
using FModel.PakReader.Parsers.PropertyTagData;
@@ -62,20 +61,7 @@ namespace FModel.PakReader.Parsers.Class
Dict[key] = obj;
}
}
else
{
Dict[val.ToString()] = null;
if (!isNonZero)
{
// We are lucky: We don't know this property but it also has no content
DebugHelper.WriteLine($"{type ?? "Unknown"}: Unknown property for {GetType().Name} with value {val} but it's zero so we are good");
}
else
{
DebugHelper.WriteLine($"{type ?? "Unknown"}: Unknown property for {GetType().Name} with value {val}. Can't proceed serialization (Serialized {Dict.Count} properties till now)");
//throw new FileLoadException($"Unknown property for {GetType().Name} with value {val}. Can't proceed serialization");
}
}
else Dict[val.ToString()] = null;
} while (it.MoveNext());
if (!structFallback && reader.ReadInt32() != 0/* && reader.Position + 16 <= maxSize*/)

View File

@@ -21,7 +21,7 @@ namespace FModel.PakReader.Parsers
public override FNameEntrySerialized[] NameMap { get; }
private IUExport[] _dataExports;
private Stream _ubulk;
private readonly Stream _ubulk;
public override IUExport[] DataExports {
get
{
@@ -42,11 +42,9 @@ namespace FModel.PakReader.Parsers
}
}
private Dictionary<FPackageObjectIndex, string> _importMappings;
public IoPackageReader(Stream uasset, Stream ubulk, FIoGlobalData globalData, FFileIoStoreReader reader, bool onlyInfo = false) : this(new BinaryReader(uasset),
ubulk, globalData, reader, onlyInfo) { }
public IoPackageReader(BinaryReader uasset, Stream ubulk, FIoGlobalData globalData, FFileIoStoreReader reader, bool onlyInfo = false)
public IoPackageReader(Stream uasset, Stream ubulk, FIoGlobalData globalData, bool onlyInfo = false) : this(new BinaryReader(uasset),
ubulk, globalData, onlyInfo) { }
public IoPackageReader(BinaryReader uasset, Stream ubulk, FIoGlobalData globalData, bool onlyInfo = false)
{
Loader = uasset;
_ubulk = ubulk;
@@ -57,9 +55,9 @@ namespace FModel.PakReader.Parsers
var nameHashes = new List<ulong>();
if (Summary.NameMapNamesSize > 0)
{
Loader.BaseStream.Position = Summary.NameMapNamesOffset;
Loader.BaseStream.Seek(Summary.NameMapNamesOffset, SeekOrigin.Begin);
var nameMapNames = Loader.ReadBytes(Summary.NameMapNamesSize);
Loader.BaseStream.Position = Summary.NameMapHashesOffset;
Loader.BaseStream.Seek(Summary.NameMapHashesOffset, SeekOrigin.Begin);
var nameMapHashes = Loader.ReadBytes(Summary.NameMapHashesSize);
FNameEntrySerialized.LoadNameBatch(nameMap, nameHashes, nameMapNames, nameMapHashes);
@@ -67,7 +65,7 @@ namespace FModel.PakReader.Parsers
NameMap = nameMap.ToArray();
Loader.BaseStream.Position = Summary.ImportMapOffset;
Loader.BaseStream.Seek(Summary.ImportMapOffset, SeekOrigin.Begin);
var importMapCount = (Summary.ExportMapOffset - Summary.ImportMapOffset) / /*sizeof(FPackageObjectIndex)*/ sizeof(ulong);
ImportMap = new FPackageObjectIndex[importMapCount];
for (int i = 0; i < importMapCount; i++)
@@ -75,7 +73,7 @@ namespace FModel.PakReader.Parsers
ImportMap[i] = new FPackageObjectIndex(Loader);
}
Loader.BaseStream.Position = Summary.ExportMapOffset;
Loader.BaseStream.Seek(Summary.ExportMapOffset, SeekOrigin.Begin);
var exportMapCount = (Summary.ExportBundlesOffset - Summary.ExportMapOffset) / FExportMapEntry.SIZE;
ExportMap = new FExportMapEntry[exportMapCount];
for (int i = 0; i < exportMapCount; i++)
@@ -89,10 +87,9 @@ namespace FModel.PakReader.Parsers
private void ReadContent()
{
Loader.BaseStream.Position = Summary.GraphDataOffset;
Loader.BaseStream.Seek(Summary.GraphDataOffset, SeekOrigin.Begin);
var referencedPackagesCount = Loader.ReadInt32();
var graphData = new (FPackageId importedPackageId, FArc[] arcs)[referencedPackagesCount];
_importMappings = new Dictionary<FPackageObjectIndex, string>(referencedPackagesCount);
FakeImportMap = new List<FObjectResource>();
for (int i = 0; i < ImportMap.Length; i++)
FakeImportMap.Add(new FObjectResource(new FName(), new FPackageIndex()));
@@ -101,19 +98,15 @@ namespace FModel.PakReader.Parsers
var importedPackageId = new FPackageId(Loader);
var arcs = Loader.ReadTArray(() => new FArc(Loader));
graphData[i] = (importedPackageId, arcs);
var importedPackageName = Creator.Utils.GetFullPath(importedPackageId)
?.Replace($"{Folders.GetGameName()}/Content", "Game");
var package = Creator.Utils.GetPropertyPakPackage(importedPackageName) as IoPackage;
if (package == null) continue;
string importedPackageName = Creator.Utils.GetFullPath(importedPackageId)?.Replace($"{Folders.GetGameName()}/Content", "Game");
if (!(Creator.Utils.GetPropertyPakPackage(importedPackageName) is IoPackage package)) continue;
foreach (var export in package.Reader.ExportMap)
{
var realImportIndex = Array.FindIndex(ImportMap, it => it == export.GlobalImportIndex);
if (realImportIndex > -1)
{
var nextIndex = FakeImportMap.Count;
FakeImportMap[realImportIndex] = new FObjectResource(new FName(export.ObjectName.String), new FPackageIndex(this, -(nextIndex + 1)));
var outerResource = new FObjectResource(new FName(package.Reader.Summary.Name.String), new FPackageIndex());
FakeImportMap.Add(outerResource);
FakeImportMap[realImportIndex] = new FObjectResource(new FName(export.ObjectName.String), new FPackageIndex(this, -(FakeImportMap.Count + 1)));
FakeImportMap.Add(new FObjectResource(new FName(package.Reader.Summary.Name.String), new FPackageIndex()));
}
}
}
@@ -143,19 +136,18 @@ namespace FModel.PakReader.Parsers
exportType = new FName("Unknown");
}
Loader.BaseStream.Position = currentExportDataOffset;
Loader.BaseStream.Seek(currentExportDataOffset, SeekOrigin.Begin);
if (Globals.TypeMappings.TryGetValue(exportType.String, out var properties))
{
_dataExports[i] = exportType.String switch
{
"Texture2D" => new UTexture2D(this, properties, _ubulk, ExportMap.Sum(e => (long) e.CookedSerialSize) + beginExportOffset),
"TextureCube" => new UTexture2D(this, properties, _ubulk, ExportMap.Sum(e => (long) e.CookedSerialSize) + beginExportOffset),
"VirtualTexture2D" => new UTexture2D(this, properties, _ubulk, ExportMap.Sum(e => (long) e.CookedSerialSize) + beginExportOffset),
"Texture2D" => new UTexture2D(this, properties, _ubulk, ExportMap.Sum(e => (long)e.CookedSerialSize) + beginExportOffset),
"TextureCube" => new UTexture2D(this, properties, _ubulk, ExportMap.Sum(e => (long)e.CookedSerialSize) + beginExportOffset),
"VirtualTexture2D" => new UTexture2D(this, properties, _ubulk, ExportMap.Sum(e => (long)e.CookedSerialSize) + beginExportOffset),
"CurveTable" => new UCurveTable(this, properties),
"DataTable" => new UDataTable(this, properties, exportType.String),
//"FontFace" => new UFontFace(this, ubulk),
"SoundWave" => new USoundWave(this, properties, _ubulk, ExportMap.Sum(e => (long) e.CookedSerialSize) + beginExportOffset),
"SoundWave" => new USoundWave(this, properties, _ubulk, ExportMap.Sum(e => (long)e.CookedSerialSize) + beginExportOffset),
//"StringTable" => new UStringTable(this),
//"AkMediaAssetData" => new UAkMediaAssetData(this, ubulk, ExportMap.Sum(e => e.SerialSize) + PackageFileSummary.TotalHeaderSize),
_ => new UObject(this, properties, type: exportType.String),

View File

@@ -29,7 +29,7 @@ namespace FModel.PakReader.Parsers.Objects
{
foreach (FName gp in gpt)
{
if (gp.String.StartsWith(startWith))
if (gp.String != null && gp.String.StartsWith(startWith))
{
fname = gp;
return true;
@@ -45,7 +45,7 @@ namespace FModel.PakReader.Parsers.Objects
foreach (FName gp in gpt)
{
foreach (string s in startWith)
if (gp.String.StartsWith(s))
if (gp.String != null && gp.String.StartsWith(s))
ret.Add(gp.String);
}
return ret;

View File

@@ -44,8 +44,6 @@ namespace FModel.PakReader.Parsers.Objects
{
return new FObjectExport(ioReader, AsExport);
}
Debugger.Break();
}
}
return null;

View File

@@ -344,7 +344,7 @@ namespace FModel.Utils
if (uexp != null)
package = new PakPackage(uasset, uexp, ubulk);
else
package = new IoPackage(uasset, ubulk, ioStoreEntry);
package = new IoPackage(uasset, ubulk);
#if !DEBUG
_CachedFiles[entry] = new Dictionary<Package, ArraySegment<byte>[]>
{

View File

@@ -107,7 +107,7 @@ namespace FModel.ViewModels.MenuItem
public static bool AtLeastOnePak(this ObservableCollection<dynamic> o) =>
Application.Current.Dispatcher.Invoke(() => o.Any(x => !x.GetType().Equals(typeof(Separator)) && x.PakFile != null));
public static bool AtLeastOnePakWithKey(this ObservableCollection<dynamic> o) =>
Application.Current.Dispatcher.Invoke(() => o.Any(x => !x.GetType().Equals(typeof(Separator)) && x.PakFile != null && (x.PakFile.AesKey != null || !x.PakFile.Info.bEncryptedIndex)));
Application.Current.Dispatcher.Invoke(() => o.GetMenuItemsWithReaders().Any(x => x.IsEnabled));
public static IEnumerable<PakMenuItemViewModel> GetMenuItemsWithReaders(this ObservableCollection<dynamic> o) =>
Application.Current.Dispatcher.Invoke(() => o.Where(x => !x.GetType().Equals(typeof(Separator)) && x.HasReader).Select(x => (PakMenuItemViewModel)x));
public static IEnumerable<PakMenuItemViewModel> GetMenuItemsWithPakFiles(this ObservableCollection<dynamic> o) =>

View File

@@ -1,6 +1,5 @@
using FModel.Windows.SoundPlayer.Visualization;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows;
namespace FModel.ViewModels.SoundPlayer

View File

@@ -28,9 +28,10 @@
<Grid Grid.Row="1" MinHeight="45">
<DockPanel Margin="5,0">
<Button Grid.Row="6" Grid.Column="1" DockPanel.Dock="Left" Height="20" Margin="5,0"
<Button x:Name="ResetBtn" Grid.Row="6" Grid.Column="1" DockPanel.Dock="Left" Height="20" Margin="5,0"
Content="{x:Static properties:Resources.ResetSettings}" Padding="5,2,5,2"
HorizontalAlignment="Left" Style="{StaticResource RedButton}" Click="OnDeleteSettings"/>
HorizontalAlignment="Left" Style="{StaticResource RedButton}" Click="OnDeleteSettings"
Visibility="Hidden"/>
<!-- Cancel Button -->
<Button Name="Button_Cancel" MinWidth="88" MaxWidth="160" Height="20" Margin="5,0" HorizontalAlignment="Right" Visibility="Collapsed" IsCancel="True"

View File

@@ -126,13 +126,14 @@ namespace FModel.Windows.DarkMessageBox
DisplayButtons(MessageBoxButton.OK);
}
internal DarkMessageBox(string message, string caption, MessageBoxButton button, MessageBoxImage image)
internal DarkMessageBox(string message, string caption, MessageBoxButton button, MessageBoxImage image, bool showReset = false)
{
InitializeComponent();
Message = message;
Caption = caption;
Image_MessageBox.Visibility = Visibility.Collapsed;
if (showReset) ResetBtn.Visibility = Visibility.Visible;
DisplayButtons(button);
DisplayImage(image);

View File

@@ -93,9 +93,9 @@ namespace FModel.Windows.DarkMessageBox
/// <param name="button">A System.Windows.MessageBoxButton value that specifies which button or buttons to display.</param>
/// <param name="icon">A System.Windows.MessageBoxImage value that specifies the icon to display.</param>
/// <returns>A System.Windows.MessageBoxResult value that specifies which message box button is clicked by the user.</returns>
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon)
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, bool showReset = false)
{
DarkMessageBox msg = new DarkMessageBox(messageBoxText, caption, button, icon);
DarkMessageBox msg = new DarkMessageBox(messageBoxText, caption, button, icon, showReset);
msg.ShowDialog();
return msg.Result;

View File

@@ -38,7 +38,14 @@ namespace FModel.Windows.SoundPlayer
{
get
{
return CanSeek ? (long)(_vorbisReader.TotalTime.TotalSeconds * _waveFormat.SampleRate * _waveFormat.Channels) : 0;
try
{
return CanSeek ? (long)(_vorbisReader.TotalTime.TotalSeconds * _waveFormat.SampleRate * _waveFormat.Channels) : 0;
}
catch (Exception)
{
return 0;
}
}
}