public void TestEncode() { //Debug.WriteLine(Environment.CurrentDirectory); uint targetKey = 504890837; //give your model key var resPath = Path.Combine(Environment.CurrentDirectory, @"..\..\Res"); foreach (var file in Directory.EnumerateFiles(resPath)) { if (!file.ToLowerInvariant().EndsWith(".psb")) { continue; } var fileName = Path.GetFileNameWithoutExtension(file).Split(new[] { '-' }, 2); //rename your file as key-name.psb if (fileName.Length < 2) { continue; } var key = UInt32.Parse(fileName[0]); if (key != targetKey) { continue; } PsbFile psb = new PsbFile(file); psb.EncodeToFile(targetKey, file + ".pure", EncodeMode.Encrypt, EncodePosition.Auto); } }
static bool Convert(uint?key, string path) { if (!key.HasValue) { Console.WriteLine("Key not valid."); return(false); } if (!File.Exists(path)) { Console.WriteLine($"File:{path} not exists."); return(false); } try { PsbFile psb = new PsbFile(path); if (psb.Version > 2) { if (psb.TestHeaderEncrypted()) //Decrypt { psb.EncodeToFile(key.Value, path + ".decrypted", EncodeMode.Decrypt); } else { psb.EncodeToFile(key.Value, path + ".encrypted", EncodeMode.Encrypt); } } else { if (psb.TestBodyEncrypted()) //Decrypt { psb.EncodeToFile(key.Value, path + ".decrypted", EncodeMode.Decrypt); } else { psb.EncodeToFile(key.Value, path + ".encrypted", EncodeMode.Encrypt); } } } catch (Exception e) { Console.WriteLine("Error: This file is not valid."); Console.WriteLine(e); return(false); } return(true); }