This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes global state argument passing
- Loading branch information
Showing
5 changed files
with
88 additions
and
125 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using PKHeX.Core; | ||
using PKHeX.Core.AutoMod; | ||
|
||
namespace CoreConsole | ||
{ | ||
internal static class ConsoleLegalizer | ||
{ | ||
public static PKM Legalize(PKM pk, GameVersion ver, LegalityAnalysis old = null) | ||
{ | ||
if (old != null) | ||
Debug.WriteLine(old.Report()); | ||
|
||
var sav = SaveUtil.GetBlankSAV(ver, "PKHeX"); | ||
var updated = sav.Legalize(pk); | ||
var la = new LegalityAnalysis(updated); | ||
if (!la.Valid) | ||
return pk; | ||
|
||
Console.WriteLine("===================================="); | ||
Console.WriteLine("= Legalized with Auto Legality Mod ="); | ||
Console.WriteLine("===================================="); | ||
Console.WriteLine(la.Report(true)); | ||
return updated; | ||
} | ||
|
||
public static PKM GetLegalPKM(PKM pk, string ver) | ||
{ | ||
var la = new LegalityAnalysis(pk); | ||
if (la.Valid) | ||
return pk; | ||
|
||
var parsed = Enum.TryParse<GameVersion>(ver, true, out var game); | ||
if (!parsed) | ||
return pk; | ||
return Legalize(pk, game, la); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,73 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using CoreConsole.APIs; | ||
using PKHeX.Core; | ||
|
||
namespace CoreConsole | ||
{ | ||
class ConsoleIndex | ||
internal static class Program | ||
{ | ||
public static PKM pk; | ||
static void Main(string[] args) | ||
private static readonly string appPath = Environment.CurrentDirectory; | ||
private const string RequestLegalityCheck = "-l"; | ||
private const string RequestLegalization = "-alm"; | ||
|
||
private static void Main(string[] args) | ||
{ | ||
string appPath = Environment.CurrentDirectory; | ||
var pk = CreatePKMfromArgs(args); | ||
|
||
Initialize(args); | ||
if (args.Contains("-l")) | ||
if (args.Contains(RequestLegalityCheck)) | ||
{ | ||
// Legality API calls | ||
var lc = new LegalityCheck(pk); | ||
if (args.Contains("--verbose")) Console.WriteLine(lc.VerboseReport); | ||
else Console.WriteLine(lc.Report); | ||
var lc = new LegalityAnalysis(pk); | ||
var verbose = args.Contains("--verbose"); | ||
Console.WriteLine(lc.Report(verbose)); | ||
} | ||
if (args.Contains("-alm")) | ||
|
||
if (!args.Contains(RequestLegalization)) | ||
return; | ||
|
||
if (!args.Contains("--version")) | ||
{ | ||
if (!args.Contains("--version")) Console.WriteLine("Specify version with the [--version] tag"); | ||
else | ||
{ | ||
var alm = new AutoLegality(pk, args[Array.IndexOf(args, "--version") + 1]); | ||
if (alm != null) | ||
{ | ||
if (!args.Contains("-o")) | ||
{ | ||
string output = Util.CleanFileName(alm.GetLegalPKM().FileName); | ||
File.WriteAllBytes(Path.Combine(appPath, "output", output), alm.GetLegalPKM().DecryptedBoxData); | ||
} else | ||
{ | ||
string output = GetOutputPath(args); | ||
File.WriteAllBytes(output, alm.GetLegalPKM().DecryptedBoxData); | ||
} | ||
} | ||
else Console.WriteLine("Invalid version"); | ||
} | ||
Console.WriteLine("Specify version with the [--version] tag"); | ||
return; | ||
} | ||
|
||
var ver = GetArgVal(args, "--version"); | ||
pk = ConsoleLegalizer.GetLegalPKM(pk, ver); | ||
var outPath = GetOutputPath(args, pk); | ||
File.WriteAllBytes(outPath, pk.DecryptedBoxData); | ||
} | ||
|
||
private static string GetOutputPath(string[] args, PKM p) | ||
{ | ||
if (args.Contains("-o")) | ||
return GetArgVal(args, "-o"); | ||
return Path.Combine(appPath, "output", Util.CleanFileName(p.FileName)); | ||
} | ||
private static void Initialize(string[] args) | ||
|
||
private static PKM CreatePKMfromArgs(string[] args) | ||
{ | ||
// check -i for input and get file path in the next arg | ||
if (args.Contains("-i")) | ||
{ | ||
string path = GetFilePath(args); | ||
byte[] data = File.ReadAllBytes(path); | ||
pk = PKMConverter.GetPKMfromBytes(data); | ||
var path = GetArgVal(args, "-i"); | ||
var data = File.ReadAllBytes(path); | ||
return PKMConverter.GetPKMfromBytes(data); | ||
} | ||
else | ||
|
||
var gameStr = GetArgVal(args, "--version"); | ||
var parsed = Enum.TryParse<GameVersion>(gameStr, true, out var game); | ||
if (!parsed) | ||
{ | ||
string set = args[Array.IndexOf(args, "--set") + 1]; | ||
bool valid = Enum.TryParse<GameVersion>(args[Array.IndexOf(args, "--version") + 1], true, out var game); | ||
var template = PKMConverter.GetBlank(game.GetGeneration(), game); | ||
template.ApplySetDetails(new ShowdownSet(set.Split(new string[] { "\\n" }, StringSplitOptions.None))); | ||
pk = template; | ||
Console.WriteLine("Invalid version specified: " + gameStr); | ||
game = GameVersion.Any; | ||
} | ||
} | ||
|
||
private static string GetFilePath(string[] args) | ||
{ | ||
return args[Array.IndexOf(args, "-i") + 1]; | ||
} | ||
|
||
private static string GetOutputPath(string[] args) | ||
{ | ||
return args[Array.IndexOf(args, "-o") + 1]; | ||
var showdownSet = GetArgVal(args, "--set"); | ||
var template = PKMConverter.GetBlank(game.GetGeneration(), game); | ||
template.ApplySetDetails(new ShowdownSet(showdownSet.Split(new [] { "\\n" }, StringSplitOptions.None))); | ||
return template; | ||
} | ||
|
||
private static string GetArgVal(string[] args, string modifier) => args[Array.IndexOf(args, modifier) + 1]; | ||
} | ||
} |