just saving this

This commit is contained in:
Asval
2019-05-28 20:21:58 +02:00
parent dfb6d5e456
commit 2b4b1bd347
15 changed files with 504 additions and 353 deletions

View File

@@ -12,6 +12,12 @@ namespace FModel
{
class DynamicPAKs
{
/// <summary>
/// get url content as string with authentication
/// </summary>
/// <param name="url"></param>
/// <param name="auth"></param>
/// <returns> url content </returns>
public static string GetEndpoint(string url, bool auth)
{
string content = string.Empty;
@@ -81,6 +87,12 @@ namespace FModel
return Enumerable.Range(0, str.Length / chunkSize)
.Select(i => str.Substring(i * chunkSize, chunkSize));
}
/// <summary>
/// split KeychainPart each 8 letter
/// for each of these letters, convert to hexadecimal as string
/// </summary>
/// <param name="KeychainPart"></param>
/// <returns> the guid (ie 17722063-2246354315-4143272431-3887619937) </returns>
public static string getPakGuidFromKeychain(string[] KeychainPart)
{
IEnumerable<string> guid = SplitGuid(KeychainPart[0], 8);

View File

@@ -13,6 +13,12 @@ namespace FModel
{
public static string ItemIconPath { get; set; }
/// <summary>
/// if user doesn't want featured image, make WasFeatured false and move to SearchAthIteDefIcon
/// else search or guess the display asset, if found move to SearchFeaturedIcon, if not found move to SearchAthIteDefIcon
/// </summary>
/// <param name="theItem"></param>
/// <param name="featured"></param>
public static void GetItemIcon(ItemsIdParser theItem, bool featured = false)
{
if (featured == false)
@@ -37,6 +43,12 @@ namespace FModel
}
}
}
/// <summary>
/// extract, serialize, get Large or Small image for HeroDefinition or WeaponDefinition
/// if no HeroDefinition and WeaponDefinition move to SearchLargeSmallIcon
/// </summary>
/// <param name="theItem"></param>
public static void SearchAthIteDefIcon(ItemsIdParser theItem)
{
if (theItem.HeroDefinition != null)
@@ -123,6 +135,11 @@ namespace FModel
else
SearchLargeSmallIcon(theItem);
}
/// <summary>
/// convert Large or Small image to a png image
/// </summary>
/// <param name="theItem"></param>
private static void SearchLargeSmallIcon(ItemsIdParser theItem)
{
if (theItem.LargePreviewImage != null)
@@ -140,6 +157,15 @@ namespace FModel
ItemIconPath = JohnWick.AssetToTexture2D(textureFile);
}
}
/// <summary>
/// With GetItemIcon we already know if manualSeach is True or False
/// manualSearch False: extract, serialize the catalogFile and parse to get and convert the featured file to a png image
/// manualSearch True: if the catalogFile is in AllpaksDictionary (is known) do same thing as manualSearch False
/// </summary>
/// <param name="theItem"></param>
/// <param name="catName"></param>
/// <param name="manualSearch"></param>
public static void SearchFeaturedIcon(ItemsIdParser theItem, string catName, bool manualSearch = false)
{
if (manualSearch == false)
@@ -261,6 +287,13 @@ namespace FModel
GetItemIcon(theItem);
}
}
/// <summary>
/// This is only triggered if ThePak.CurrentUsedItem is a weapon id, it's to display the bullet type
/// extract, serialize and parse the ammoFile, search a Large or Small icon, display this icon at the top left of the rarity image
/// </summary>
/// <param name="ammoFile"></param>
/// <param name="toDrawOn"></param>
public static void GetAmmoData(string ammoFile, Graphics toDrawOn)
{
string ammoFilePath;
@@ -291,12 +324,12 @@ namespace FModel
{
itemIcon = new Bitmap(bmpTemp);
}
toDrawOn.DrawImage(Forms.Settings.ResizeImage(itemIcon, 64, 64), new Point(6, 6));
toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 64, 64), new Point(6, 6));
}
else
{
Image itemIcon = Resources.unknown512;
toDrawOn.DrawImage(Forms.Settings.ResizeImage(itemIcon, 64, 64), new Point(6, 6));
toDrawOn.DrawImage(ImageUtilities.ResizeImage(itemIcon, 64, 64), new Point(6, 6));
}
}
}

View File

@@ -6,7 +6,12 @@ namespace FModel
{
class Rarity
{
public static Image GetRarityImage(ItemsIdParser theItem)
/// <summary>
/// check the rarity and return the right image
/// </summary>
/// <param name="theItem"></param>
/// <returns> the resource image depending on the rarity </returns>
private static Image GetRarityImage(ItemsIdParser theItem)
{
switch (theItem.Rarity)
{
@@ -27,7 +32,14 @@ namespace FModel
return Resources.U512;
}
}
public static Image GetSeriesImage(ItemsIdParser theItem)
/// <summary>
/// check the series and return the right image
/// if no series known, return the normal item rarity image with GetRarityImage
/// </summary>
/// <param name="theItem"></param>
/// <returns> the resource image depending on the series </returns>
private static Image GetSeriesImage(ItemsIdParser theItem)
{
if (theItem.Series == "MarvelSeries")
{
@@ -38,7 +50,15 @@ namespace FModel
return GetRarityImage(theItem);
}
}
public static Image GetSpecialModeImage(ItemsIdParser theItem, string specialMode)
/// <summary>
/// if specialMode isn't null and is known return the right image
/// if specialMode is unknown, return the normal item rarity image with GetRarityImage
/// </summary>
/// <param name="theItem"></param>
/// <param name="specialMode"></param>
/// <returns> the resource image depending on specialMode </returns>
private static Image GetSpecialModeImage(ItemsIdParser theItem, string specialMode)
{
if (specialMode == "ammo")
{
@@ -49,6 +69,13 @@ namespace FModel
return GetRarityImage(theItem);
}
}
/// <summary>
/// just draw the rarity
/// </summary>
/// <param name="theItem"></param>
/// <param name="toDrawOn"></param>
/// <param name="specialMode"></param>
public static void DrawRarity(ItemsIdParser theItem, Graphics toDrawOn, string specialMode = null)
{
Image rarityBg;

View File

@@ -16,6 +16,13 @@ namespace FModel
private static string[] myArray { get; set; }
private static string currentPakToCheck { get; set; }
/// <summary>
/// Normal pak file: using AllpaksDictionary, it tells you the pak name depending on currentItem. Using this pak name and PaksMountPoint we get the mount point
/// Dynamic pak file: It's made so we already know the name of the pak, so we just use PaksMountPoint to get the mount point
/// </summary>
/// <param name="currentItem"></param>
/// <param name="DynamicPak"></param>
/// <returns> the mount point as string, used to create subfolders when extracting or create the tree when loading all paks </returns>
private static string GetMountPointFromDict(string currentItem, bool DynamicPak = false)
{
if (DynamicPak == true)
@@ -23,6 +30,14 @@ namespace FModel
else
return ThePak.PaksMountPoint[ThePak.AllpaksDictionary[currentItem ?? throw new InvalidOperationException()] ?? throw new InvalidOperationException()];
}
/// <summary>
/// just the method to create subfolders using GetMountPointFromDict and write the file from myResults with its byte[] data
/// </summary>
/// <param name="currentItem"></param>
/// <param name="myResults"></param>
/// <param name="data"></param>
/// <returns> the path to this brand new created file </returns>
private static string WriteFile(string currentItem, string myResults, byte[] data)
{
if (ThePak.CurrentUsedPakGuid != null && ThePak.CurrentUsedPakGuid != "0-0-0-0")
@@ -41,6 +56,14 @@ namespace FModel
}
}
/// <summary>
/// We get the file list of currentPak, we find all files that matched our currentItem, for each result we get its indexes (it's used to get its data)
/// Then we can use WriteFile to write each results with its data
/// If currentPak is the same twice in a row, we do not try to get a new file list
/// </summary>
/// <param name="currentPak"></param>
/// <param name="currentItem"></param>
/// <returns> the path of the last created file (usually the uexp file but we don't care about the extension, so it's fine) </returns>
public static string ExtractAsset(string currentPak, string currentItem)
{
if (currentPak != currentPakToCheck)
@@ -69,6 +92,12 @@ namespace FModel
currentPakToCheck = currentPak;
return AssetPath;
}
/// <summary>
/// just convert the asset to a png image with some exceptions in case AssetName is a material
/// </summary>
/// <param name="AssetName"></param>
/// <returns> the path to the png image </returns>
public static string AssetToTexture2D(string AssetName)
{
string textureFilePath;
@@ -81,7 +110,7 @@ namespace FModel
string TexturePath = string.Empty;
if (textureFilePath != null && (textureFilePath.Contains("MI_UI_FeaturedRenderSwitch_") || textureFilePath.Contains("M_UI_ChallengeTile_PCB") || textureFilePath.Contains("Wraps\\FeaturedMaterials\\") || textureFilePath.Contains("M-Wraps-StreetDemon")))
{
return GetRenderSwitchMaterialTexture(AssetName, textureFilePath);
return GetRenderSwitchMaterialTexture(textureFilePath);
}
else if (textureFilePath != null)
{
@@ -91,7 +120,13 @@ namespace FModel
}
return TexturePath;
}
public static string GetRenderSwitchMaterialTexture(string AssetName, string AssetPath)
/// <summary>
/// serialize the material to get the texture and convert this texture to a png image
/// </summary>
/// <param name="AssetPath"></param>
/// <returns> the path to the png image </returns>
public static string GetRenderSwitchMaterialTexture(string AssetPath)
{
string TexturePath = string.Empty;
if (AssetPath.Contains(".uasset") || AssetPath.Contains(".uexp") || AssetPath.Contains(".ubulk"))

View File

@@ -0,0 +1,41 @@
using FModel.Properties;
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Runtime.InteropServices;
namespace FModel
{
class FontUtilities
{
public static PrivateFontCollection _pfc = new PrivateFontCollection();
public static StringFormat _centeredString = new StringFormat();
public static StringFormat _rightString = new StringFormat();
public static StringFormat _centeredStringLine = new StringFormat();
private static int _fontLength { get; set; }
private static byte[] _fontdata { get; set; }
/// <summary>
/// Register font in Resources to the PrivateFontCollection to use them in IconGenerator or other stuff
/// </summary>
public static void SetFont()
{
_fontLength = Resources.BurbankBigCondensed_Bold.Length;
_fontdata = Resources.BurbankBigCondensed_Bold;
IntPtr weirdData = Marshal.AllocCoTaskMem(_fontLength);
Marshal.Copy(_fontdata, 0, weirdData, _fontLength);
_pfc.AddMemoryFont(weirdData, _fontLength);
_fontLength = Resources.BurbankBigCondensed_Black.Length;
_fontdata = Resources.BurbankBigCondensed_Black;
IntPtr weirdData2 = Marshal.AllocCoTaskMem(_fontLength);
Marshal.Copy(_fontdata, 0, weirdData2, _fontLength);
_pfc.AddMemoryFont(weirdData2, _fontLength);
_centeredString.Alignment = StringAlignment.Center;
_rightString.Alignment = StringAlignment.Far;
_centeredStringLine.LineAlignment = StringAlignment.Center;
_centeredStringLine.Alignment = StringAlignment.Center;
}
}
}

View File

@@ -0,0 +1,74 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace FModel
{
class ImageUtilities
{
/// <summary>
/// Set the opacity of an Image -> convert Image to Bitmap, create a graphic object of the Bitmap, create a color matrix object to set the opacity
/// </summary>
/// <param name="image"></param>
/// <param name="opacity"></param>
/// <returns> the Bitmap image with its new opacity </returns>
public static Image SetImageOpacity(Image image, float opacity)
{
//create a Bitmap the size of the image provided
Bitmap bmp = new Bitmap(image.Width, image.Height);
//create a graphics object from the image
using (Graphics gfx = Graphics.FromImage(bmp))
{
//create a color matrix object
ColorMatrix matrix = new ColorMatrix();
//set the opacity
matrix.Matrix33 = opacity;
//create image attributes
ImageAttributes attributes = new ImageAttributes();
//set the color(opacity) of the image
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
//now draw the image
gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
}
return bmp;
}
/// <summary>
/// Resize an Image
/// </summary>
/// <param name="image"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns> the resized image </returns>
public static Bitmap ResizeImage(Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
var destImage = new Bitmap(width, height);
destImage.SetResolution(image.HorizontalResolution, image.VerticalResolution);
using (var graphics = Graphics.FromImage(destImage))
{
graphics.CompositingMode = CompositingMode.SourceCopy;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
using (var wrapMode = new ImageAttributes())
{
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
graphics.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, wrapMode);
}
}
return destImage;
}
}
}

View File

@@ -0,0 +1,94 @@
using FModel.Properties;
using System;
using System.Diagnostics;
using System.IO;
using System.Security.AccessControl;
using System.Security.Principal;
namespace FModel
{
class Utilities
{
/// <summary>
/// OpenWithDefaultProgramAndNoFocus is used to automatically open sound file once they are converted
/// </summary>
/// <param name="path"> path is the path to the converted sound file (in "Sounds" subfolder) </param>
public static void OpenWithDefaultProgramAndNoFocus(string path)
{
Process fileopener = new Process();
fileopener.StartInfo.FileName = "explorer";
fileopener.StartInfo.Arguments = "\"" + path + "\"";
fileopener.Start();
}
/// <summary>
/// just create the default folders FModel needs to work
/// </summary>
public static void CreateDefaultFolders()
{
if (!Directory.Exists(App.DefaultOutputPath + "\\Backup\\"))
Directory.CreateDirectory(App.DefaultOutputPath + "\\Backup\\");
if (!Directory.Exists(App.DefaultOutputPath + "\\Extracted\\"))
Directory.CreateDirectory(App.DefaultOutputPath + "\\Extracted\\");
if (!Directory.Exists(App.DefaultOutputPath + "\\Icons\\"))
Directory.CreateDirectory(App.DefaultOutputPath + "\\Icons\\");
if (!Directory.Exists(App.DefaultOutputPath + "\\Sounds\\"))
Directory.CreateDirectory(App.DefaultOutputPath + "\\Sounds\\");
}
/// <summary>
/// actually idk if it's useful, i added this for Admin windows account, when FModel can't even use CreateDefaultFolders
/// </summary>
/// <param name="folderPath"></param>
public static void SetFolderPermission(string folderPath)
{
var directoryInfo = new DirectoryInfo(folderPath);
var directorySecurity = directoryInfo.GetAccessControl();
var currentUserIdentity = WindowsIdentity.GetCurrent();
var fileSystemRule = new FileSystemAccessRule(currentUserIdentity.Name,
FileSystemRights.Read,
InheritanceFlags.ObjectInherit |
InheritanceFlags.ContainerInherit,
PropagationFlags.None,
AccessControlType.Allow);
directorySecurity.AddAccessRule(fileSystemRule);
directoryInfo.SetAccessControl(directorySecurity);
}
/// <summary>
/// By default the output folder is the Documents folder, however if user wanna change, once FModel restart SetOutputFolder is called
/// </summary>
public static void SetOutputFolder()
{
App.DefaultOutputPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\FModel"; //DOCUMENTS FOLDER BY DEFAULT
if (string.IsNullOrEmpty(Settings.Default.ExtractOutput))
{
Settings.Default.ExtractOutput = App.DefaultOutputPath;
Settings.Default.Save();
}
else
{
App.DefaultOutputPath = Settings.Default.ExtractOutput;
}
Directory.CreateDirectory(App.DefaultOutputPath);
}
/// <summary>
/// Once upon a time, it was used for shitty stuff
/// </summary>
public static void JohnWickCheck()
{
if (File.Exists(App.DefaultOutputPath + "\\john-wick-parse-modded.exe")) //2.0-
{
File.Delete(App.DefaultOutputPath + "\\john-wick-parse-modded.exe");
}
if (File.Exists(App.DefaultOutputPath + "\\john-wick-parse_custom.exe")) //2.0+
{
File.Delete(App.DefaultOutputPath + "\\john-wick-parse_custom.exe");
}
}
}
}

View File

@@ -12,6 +12,13 @@ namespace FModel
public static Dictionary<string, string> PaksMountPoint { get; set; }
public static Dictionary<string, string> AllpaksDictionary { get; set; }
/// <summary>
/// read the GUID of a the param, it's basically just reading some bytes at the end of a pak file, but it's useful to tell if the pak is dynamically encrypted
/// "0-0-0-0" for normal pak
/// "123456789-9876543210-741085209630-015975306482" for dynamic pak (these numbers are an example)
/// </summary>
/// <param name="pakPath"> path to the pak file to get its GUID </param>
/// <returns> the guid </returns>
public static string ReadPakGuid(string pakPath)
{
using (BinaryReader reader = new BinaryReader(File.Open(pakPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
@@ -29,6 +36,12 @@ namespace FModel
return guid;
}
}
/// <summary>
/// read the pak version (v8 28.05.2019), it's basically just reading one byte at the end of a pak file
/// </summary>
/// <param name="pakPath"> path to the pak file to get its version </param>
/// <returns> the version </returns>
public static string ReadPakVersion(string pakPath)
{
using (BinaryReader reader = new BinaryReader(File.Open(pakPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))