public static SKBitmap?Decode(this UTexture2D texture, FTexture2DMipMap?mip, ETexturePlatform platform = ETexturePlatform.DesktopMobile) { if (!texture.IsVirtual && mip != null) { byte[] data; SKColorType colorType; switch (platform) { case ETexturePlatform.Playstation: PlaystationDecoder.DecodeTexturePlaystation(mip, texture.Format, texture.isNormalMap, out data, out colorType); break; case ETexturePlatform.NintendoSwitch: NintendoSwitchDecoder.DecodeTextureNSW(mip, texture.Format, texture.isNormalMap, out data, out colorType); break; default: DecodeTexture(mip, texture.Format, texture.isNormalMap, out data, out colorType); break; } var width = mip.SizeX; var height = mip.SizeY; var info = new SKImageInfo(width, height, colorType, SKAlphaType.Unpremul); var bitmap = new SKBitmap(); unsafe { var pixelsPtr = NativeMemory.Alloc((nuint)data.Length); fixed(byte *p = data) { Unsafe.CopyBlockUnaligned(pixelsPtr, p, (uint)data.Length); } bitmap.InstallPixels(info, new IntPtr(pixelsPtr), info.RowBytes, (address, _) => NativeMemory.Free(address.ToPointer())); } if (!texture.bRenderNearestNeighbor) { return(bitmap); } var resized = bitmap.Resize(new SKImageInfo(width, height), SKFilterQuality.None); bitmap.Dispose(); return(resized); } return(null); }
public static SKImage?Decode(this UTexture2D texture) { if (!texture.IsVirtual && texture.GetFirstMip() is { } mip) { DecodeTexture(mip, texture.Format, out byte[] data, out var colorType); using var bitmap = new SKBitmap(new SKImageInfo(mip.SizeX, mip.SizeY, colorType, SKAlphaType.Unpremul)); unsafe { fixed(byte *p = data) { bitmap.SetPixels(new IntPtr(p)); } } return(SKImage.FromBitmap(bitmap)); } return(null); }
public static List <Texture2DMipInfo> GetTexture2DMipInfos(ExportEntry exportEntry, string cacheName) { UTexture2D texBin = exportEntry.GetBinaryData <UTexture2D>(); var mips = new List <Texture2DMipInfo>(); for (int i = 0; i < texBin.Mips.Count; i++) { UTexture2D.Texture2DMipMap binMip = texBin.Mips[i]; Texture2DMipInfo mip = new Texture2DMipInfo { Export = exportEntry, index = i, storageType = binMip.StorageType, uncompressedSize = binMip.UncompressedSize, compressedSize = binMip.CompressedSize, externalOffset = binMip.DataOffset, Mip = binMip.Mip, TextureCacheName = cacheName, //If this is ME1, this will simply be ignored in the setter width = binMip.SizeX, height = binMip.SizeY }; if (mip.width == 4 && mips.Exists(m => m.width == mip.width)) { mip.width = mips.Last().width / 2; } if (mip.height == 4 && mips.Exists(m => m.height == mip.height)) { mip.height = mips.Last().height / 2; } if (mip.width == 0) { mip.width = 1; } if (mip.height == 0) { mip.height = 1; } mips.Add(mip); } return(mips); }
public static SKImage?Decode(this UTexture2D texture, bool bNearest = false) { if (!texture.IsVirtual && texture.GetFirstMip() is { } mip) { DecodeTexture(mip, texture.Format, out byte[] data, out var colorType); var width = mip.SizeX; var height = mip.SizeY; using var bitmap = new SKBitmap(new SKImageInfo(width, height, colorType, SKAlphaType.Unpremul)); unsafe { fixed(byte *p = data) { bitmap.SetPixels(new IntPtr(p)); } } return(SKImage.FromBitmap(!bNearest ? bitmap : bitmap.Resize(new SKImageInfo(width, height), SKFilterQuality.None))); } return(null); }
public override void ParseForInfo() { ParseForReward(false); if (Object.TryGetValue(out FStructFallback urgentQuestData, "UrgentQuestData")) { if (urgentQuestData.TryGetValue(out FText eventTitle, "EventTitle")) { DisplayName = eventTitle.Text; } if (urgentQuestData.TryGetValue(out FText eventDescription, "EventDescription")) { Description = eventDescription.Text; } if (urgentQuestData.TryGetValue(out FPackageIndex alertIcon, "AlertIcon", "BountyPriceImage")) { Preview = Utils.GetBitmap(alertIcon); } } else { Description = ShortDescription; if (Object.TryGetValue(out FText completionText, "CompletionText")) { Description += "\n" + completionText.Text; } if (Object.TryGetValue(out FSoftObjectPath tandemCharacterData, "TandemCharacterData") && Utils.TryLoadObject(tandemCharacterData.AssetPathName.Text, out UObject uObject) && uObject.TryGetValue(out FSoftObjectPath tandemIcon, "EntryListIcon", "ToastIcon") && Utils.TryLoadObject(tandemIcon.AssetPathName.Text, out UObject iconObject)) { Preview = iconObject switch { UTexture2D text => Utils.GetBitmap(text), UMaterialInstanceConstant mat => Utils.GetBitmap(mat), _ => Preview }; } } if (Object.TryGetValue(out int objectiveCompletionCount, "ObjectiveCompletionCount")) { _count = objectiveCompletionCount; } if (Object.TryGetValue(out FStructFallback[] objectives, "Objectives") && objectives.Length > 0) { // actual description doesn't exist if (string.IsNullOrEmpty(Description) && objectives[0].TryGetValue(out FText description, "Description")) { Description = description.Text; } // ObjectiveCompletionCount doesn't exist if (_count == 0) { if (objectives[0].TryGetValue(out int count, "Count") && count > 1) { _count = count; } else { _count = objectives.Length; } } } if (Object.TryGetValue(out FStructFallback[] rewards, "Rewards")) { foreach (var reward in rewards) { if (!reward.TryGetValue(out FStructFallback itemPrimaryAssetId, "ItemPrimaryAssetId") || !reward.TryGetValue(out int quantity, "Quantity")) { continue; } if (!itemPrimaryAssetId.TryGetValue(out FStructFallback primaryAssetType, "PrimaryAssetType") || !itemPrimaryAssetId.TryGetValue(out FName primaryAssetName, "PrimaryAssetName") || !primaryAssetType.TryGetValue(out FName name, "Name")) { continue; } if (name.Text.Equals("Quest", StringComparison.OrdinalIgnoreCase)) { NextQuestName = primaryAssetName.Text; } else if (!_unauthorizedReward.Contains(name.Text)) { _reward = new Reward(quantity, $"{name}:{primaryAssetName}"); } } } if (_reward == null && Object.TryGetValue(out UDataTable rewardsTable, "RewardsTable")) { if (rewardsTable.TryGetDataTableRow("Default", StringComparison.InvariantCulture, out var row)) { if (row.TryGetValue(out FName templateId, "TemplateId") && row.TryGetValue(out int quantity, "Quantity")) { _reward = new Reward(quantity, templateId); } } } if (_reward == null && Object.TryGetValue(out FStructFallback[] hiddenRewards, "HiddenRewards")) { foreach (var hiddenReward in hiddenRewards) { if (!hiddenReward.TryGetValue(out FName templateId, "TemplateId") || !hiddenReward.TryGetValue(out int quantity, "Quantity")) { continue; } _reward = new Reward(quantity, templateId); break; } } _reward ??= new Reward(); }
public static SKBitmap?Decode(this UTexture2D texture, ETexturePlatform platform = ETexturePlatform.DesktopMobile) => texture.Decode(texture.GetFirstMip(), platform);