private static void Main(string[] args) { Initialize(); if (Abort) { return; } if (args.Length < 1) { using (var dialog = new OpenFileDialog()) { dialog.Title = @"Open an AssetBundle..."; dialog.Filter = @"Azurlane AssetBundle|scripts*"; dialog.CheckFileExists = true; dialog.Multiselect = false; dialog.ShowDialog(); if (File.Exists(dialog.FileName)) { args = new[] { dialog.FileName }; } else { Utils.Write(@"Please open an AssetBundle...", true, true); goto END; } } } else if (args.Length > 1) { Utils.Write(@"Invalid argument, usage: Azurlane.exe <path-to-assetbundle>", true, true); goto END; } var filePath = Path.GetFullPath(args[0]); var fileDirectoryPath = Path.GetDirectoryName(filePath); var fileName = Path.GetFileName(filePath); if (!File.Exists(filePath)) { Utils.Write(Directory.Exists(fileDirectoryPath) ? $"{args[0]} is a directory, please input a file..." : $"{args[0]} does not exists...", true, true); goto END; } if (!AssetBundleMgr.CheckAssetBundle(filePath)) { Utils.Write("Not a valid AssetBundle file...", true, true); goto END; } Clean(fileName); if (!Directory.Exists(PathMgr.Temp())) { Directory.CreateDirectory(PathMgr.Temp()); } var startTime = DateTime.Now; var index = 1; if (_listOfAction == null) { _listOfAction = new List <Action>() { () => { try { Utils.LogInfo("Copying AssetBundle to tmp workspace...", true, false); File.Copy(filePath, PathMgr.Temp(fileName), true); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during copying AssetBundle to tmp workspace", e); } }, () => { try { Utils.LogInfo("Decrypting AssetBundle...", true, false); Utils.Command($"Azcli.exe --dev --decrypt \"{PathMgr.Temp(fileName)}\""); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during decrypting AssetBundle", e); } }, () => { try { Utils.LogInfo("Unpacking AssetBundle...", true, false); Utils.Command($"Azcli.exe --dev --unpack \"{PathMgr.Temp(fileName)}\""); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during unpacking AssetBundle", e); } }, () => { try { var showDoneMessage = true; Utils.LogInfo("Decrypting Lua...", true, false); foreach (var lua in ListOfLua) { Utils.Command($"Azcli.exe --dev --unlock \"{PathMgr.Lua(fileName, lua)}\""); if (LuaMgr.CheckLuaState(PathMgr.Lua(fileName, lua)) != LuaMgr.State.Encrypted) { break; } Console.WriteLine(); Utils.LogDebug($"Failed to decrypt {Path.GetFileName(lua)}", true, true); showDoneMessage = false; } if (showDoneMessage) { Utils.Write(" <done>", false, true); } } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during decrypting Lua", e); } }, () => { try { Utils.LogInfo("Decompiling Lua...", true, false); var tasks = new List <Task>(); foreach (var lua in ListOfLua) { tasks.Add(Task.Factory.StartNew(() => { Utils.Command($"Azcli.exe --dev --decompile \"{PathMgr.Lua(fileName, lua)}\""); Utils.Write($@" {index}/{ListOfLua.Count}", false, false); index++; })); } Task.WaitAll(tasks.ToArray()); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during decompiling Lua", e); } }, () => { try { Utils.LogInfo("Cloning Lua & AssetBundle", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); if (!Directory.Exists(PathMgr.Lua(modName))) { Directory.CreateDirectory(PathMgr.Lua(modName)); } foreach (var lua in ListOfLua) { if (File.Exists(PathMgr.Lua(fileName, lua))) { File.Copy(PathMgr.Lua(fileName, lua), PathMgr.Lua(modName, lua), true); } } if (File.Exists(PathMgr.Temp(fileName))) { File.Copy(PathMgr.Temp(fileName), PathMgr.Temp(modName), true); } } } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during cloning lua & assetbundle", e); } }, () => { try { Utils.LogInfo("Cleaning...", true, false); if (File.Exists(PathMgr.Temp(fileName))) { File.Delete(PathMgr.Temp(fileName)); } if (Directory.Exists(PathMgr.Lua(fileName).Replace($"\\{DirName}", ""))) { Utils.Rmdir(PathMgr.Lua(fileName).Replace($"\\{DirName}", "")); } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during cleaning", e); } }, () => { try { Utils.LogInfo("Rewriting Lua...", true, false); Utils.Command("Azrewriter.exe"); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during rewriting Lua", e); } }, () => { try { Utils.LogInfo("Recompiling Lua...", true, false); var tasks = new List <Task>(); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); foreach (var lua in ListOfLua) { tasks.Add(Task.Factory.StartNew(() => { })); } } } Task.WaitAll(tasks.ToArray()); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during recompiling Lua", e); } }, () => { try { var showDoneMessage = true; Utils.LogInfo("Encrypting Lua...", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); foreach (var lua in ListOfLua) { Utils.Command($"Azcli.exe --dev --lock \"{PathMgr.Lua(modName, lua)}\""); if (LuaMgr.CheckLuaState(PathMgr.Lua(modName, lua)) != LuaMgr.State.Decrypted) { break; } Console.WriteLine(); Utils.LogDebug($"Failed to encrypt {mod}/{Path.GetFileName(lua)}...", true, true); showDoneMessage = false; } } } if (showDoneMessage) { Utils.Write(" <done>", false, true); } } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during encrypting Lua", e); } }, DevMode, () => { try { Utils.LogInfo("Repacking AssetBundle...", true, false); var tasks = new List <Task>(); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); tasks.Add(Task.Factory.StartNew(() => { Utils.Command($"Azcli.exe --dev --repack \"{PathMgr.Temp(modName)}\""); Utils.Write($@" {index}/{ListOfMod.Count(x => x.Value)}", false, false); index++; })); } } Task.WaitAll(tasks.ToArray()); Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during repacking AssetBundle", e); } }, () => { try { Utils.LogInfo("Encrypting AssetBundle...", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); Utils.Command($"Azcli.exe --dev --encrypt \"{PathMgr.Temp(modName)}\""); } } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during encrypting AssetBundle", e); } }, () => { try { Utils.LogInfo("Copying modified AssetBundle to original location...", true, false); foreach (var mod in ListOfMod) { if (mod.Value) { var modName = ("scripts-" + mod.Key).ToLower().Replace("_", "-"); if (File.Exists(Path.Combine(fileDirectoryPath, modName))) { File.Delete(Path.Combine(fileDirectoryPath, modName)); } File.Copy(PathMgr.Temp(modName), Path.Combine(fileDirectoryPath, modName)); } } Utils.Write(" <done>", false, true); } catch (Exception e) { Utils.Write(" <failed>", false, true); Utils.LogException("Exception detected during copying modified AssetBundle to original location", e); } } }; } try { foreach (var action in _listOfAction) { if (Abort) { break; } index = 1; action.Invoke(); } } finally { Utils.LogInfo("Cleaning...", true, true); Clean(fileName); Console.WriteLine(); Utils.Write("Finished.", true, true); var endTime = DateTime.Now; TimeSpan timeSpan = endTime - startTime; Utils.Write("Started at {0} - Ended at {1}", true, true, startTime.ToString("HH:mm"), endTime.ToString("HH:mm")); Utils.Write("{0} seconds elapsed.", true, true, timeSpan.TotalSeconds.ToString()); Console.WriteLine(); // Please don't delete this lol Utils.Write("Good work (even though you have done nothing at all).", true, true); } END: Utils.Write("Press any key to exit...", true, true); Console.ReadKey(); }
private static void Main(string[] args) { if (args.Length < 1) { using (var dialog = new OpenFileDialog()) { dialog.Title = "Open an AssetBundle..."; dialog.Filter = "Azurlane AssetBundle|scripts*"; dialog.CheckFileExists = true; dialog.Multiselect = false; dialog.ShowDialog(); if (File.Exists(dialog.FileName)) { args = new[] { dialog.FileName }; } else { Console.WriteLine("Please open an AssetBundle..."); goto END; } } } else if (args.Length > 1) { Console.WriteLine("Invalid argument, usage: Azurlane.exe <path-to-assetbundle>"); goto END; } var filePath = Path.GetFullPath(args[0]); var fileDirectoryPath = Path.GetDirectoryName(filePath); var fileName = Path.GetFileName(filePath); if (!File.Exists(filePath)) { Console.WriteLine(Directory.Exists(fileDirectoryPath) ? string.Format("{0} is a directory, please input a file...", args[0]) : string.Format("{0} does not exists...", args[0])); goto END; } if (!AssetBundleMgr.IsAssetBundleValid(filePath)) { Console.WriteLine("Not a valid AssetBundle file..."); goto END; } ConfigMgr.Initialize(); for (var i = 0; i < ListOfMod.Count; i++) { ListOfMod[i] = string.Format("{0}-{1}", fileName, ListOfMod[i]); } if (File.Exists(PathMgr.Local("Logs.txt"))) { File.Delete(PathMgr.Local("Logs.txt")); } Clean(fileName); if (!Directory.Exists(PathMgr.Temp())) { Directory.CreateDirectory(PathMgr.Temp()); } var index = 1; if (ListOfAction == null) { ListOfAction = new List <Action>() { { () => { try { Utils.pInfof("Copying AssetBundle to temporary workspace..."); File.Copy(filePath, PathMgr.Temp(fileName), true); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during copying AssetBundle to temporary workspace", e); } } }, { () => { try { Utils.pInfof("Decrypting AssetBundle..."); Utils.NewCommand(string.Format("Azcli.exe --decrypt \"{0}\"", PathMgr.Temp(fileName))); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during decrypting AssetBundle", e); } } }, { () => { try { Utils.pInfof("Unpacking AssetBundle..."); Utils.NewCommand(string.Format("Azcli.exe --unpack \"{0}\"", PathMgr.Temp(fileName))); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during unpacking AssetBundle", e); } } }, { () => { try { var showDoneMessage = true; Utils.pInfof("Decrypting Lua..."); foreach (var lua in ListOfLua) { Utils.NewCommand(string.Format("Azcli.exe --unlock \"{0}\"", PathMgr.Lua(fileName, lua))); if (LuaMgr.CheckLuaState(PathMgr.Lua(fileName, lua)) == LuaMgr.State.Encrypted) { Utils.pDebugln(string.Format("Failed to decrypt {0}", Path.GetFileName(lua))); showDoneMessage = false; } } if (showDoneMessage) { Console.Write(" <Done>\n"); } } catch (Exception e) { Utils.eLogger("Exception detected during decrypting Lua", e); } } }, { () => { try { Utils.pInfof("Decompiling Lua..."); foreach (var lua in ListOfLua) { Console.Write($" {index}/{ListOfLua.Count}"); Utils.NewCommand(string.Format("Azcli.exe --decompile \"{0}\"", PathMgr.Lua(fileName, lua))); index++; } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during decompiling Lua", e); } } }, { () => { try { Utils.pInfof("Creating a copy of Lua & AssetBundle"); foreach (var mod in ListOfMod) { if (!Directory.Exists(PathMgr.Lua(mod))) { Directory.CreateDirectory(PathMgr.Lua(mod)); } foreach (var lua in ListOfLua) { File.Copy(PathMgr.Lua(fileName, lua), PathMgr.Lua(mod, lua), true); } File.Copy(PathMgr.Temp(fileName), PathMgr.Temp(mod), true); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during creating a copy of Lua & AssetBundle", e); } } }, { () => { try { Utils.pInfof("Cleaning..."); if (File.Exists(PathMgr.Temp(fileName))) { File.Delete(PathMgr.Temp(fileName)); } if (Directory.Exists(PathMgr.Lua(fileName).Replace("\\CAB-android", ""))) { Utils.Rmdir(PathMgr.Lua(fileName).Replace("\\CAB-android", "")); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during cleaning", e); } } }, { () => { try { Utils.pInfof("Rewriting Lua..."); Utils.NewCommand("Rewriter.exe"); Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during rewriting Lua", e); } } }, { () => { try { Utils.pInfof("Recompiling Lua..."); foreach (var mod in ListOfMod) { foreach (var lua in ListOfLua) { Utils.NewCommand(string.Format("Azcli.exe --recompile \"{0}\"", PathMgr.Lua(mod, lua))); } } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during recompiling Lua", e); } } }, { () => { try { var showDoneMessage = true; Utils.pInfof("Encrypting Lua..."); foreach (var mod in ListOfMod) { foreach (var lua in ListOfLua) { Utils.NewCommand(string.Format("Azcli.exe --lock \"{0}\"", PathMgr.Lua(mod, lua))); if (LuaMgr.CheckLuaState(PathMgr.Lua(mod, lua)) == LuaMgr.State.Decrypted) { Utils.pDebugln(string.Format("Failed to encrypt {0}/{1}...", mod, Path.GetFileName(lua))); showDoneMessage = false; } } } if (showDoneMessage) { Console.Write(" <Done>\n"); } } catch (Exception e) { Utils.eLogger("Exception detected during encrypting Lua", e); } } }, { () => { try { Utils.pInfof("Repacking AssetBundle..."); foreach (var mod in ListOfMod) { Console.Write($" {index}/{ListOfMod.Count}"); Utils.NewCommand(string.Format("Azcli.exe --repack \"{0}\"", PathMgr.Temp(mod))); index++; } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during repacking AssetBundle", e); } } }, { () => { try { Utils.pInfof("Encrypting AssetBundle..."); foreach (var mod in ListOfMod) { Utils.NewCommand(string.Format("Azcli.exe --encrypt \"{0}\"", PathMgr.Temp(mod))); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during encrypting AssetBundle", e); } } }, { () => { try { Utils.pInfof("Copying modified AssetBundle to original location..."); foreach (var mod in ListOfMod) { if (File.Exists(Path.Combine(fileDirectoryPath, mod))) { File.Delete(Path.Combine(fileDirectoryPath, mod)); } File.Copy(PathMgr.Temp(mod), Path.Combine(fileDirectoryPath, mod)); } Console.Write(" <Done>\n"); } catch (Exception e) { Utils.eLogger("Exception detected during copying modified AssetBundle to original location", e); } } } }; } try { foreach (var action in ListOfAction) { if (index != 1) { index = 1; } action.Invoke(); } } finally { Utils.pInfoln("Finishing..."); Clean(fileName); Console.WriteLine(); Console.WriteLine("Finished."); } END: Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }