Skip to content

Commit

Permalink
Merge pull request #46 from hozuki/v0.7.11
Browse files Browse the repository at this point in the history
v0.7.11
  • Loading branch information
hozuki committed Feb 9, 2018
2 parents 0ce0392 + 4ffd0eb commit 2a14cbc
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 58 deletions.
5 changes: 2 additions & 3 deletions Apps/Hca2Wav/DereTore.Apps.Hca2Wav.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@
<LangVersion>6</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\..\packages\CommandLineParser.1.9.71\lib\net40\CommandLine.dll</HintPath>
<Private>True</Private>
<Reference Include="CommandLine, Version=2.2.1.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\..\packages\CommandLineParser.2.2.1\lib\net40\CommandLine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
16 changes: 8 additions & 8 deletions Apps/Hca2Wav/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
namespace DereTore.Apps.Hca2Wav {
public sealed class Options {

[ValueOption(0)]
[Value(0)]
public string InputFileName { get; set; } = string.Empty;

[Option('o', "out", HelpText = "Output file name", Required = false)]
public string OutputFileName { get; set; } = string.Empty;

[Option('a', "key1", HelpText = "Key 1 (8 hex digits)", Required = false, DefaultValue = "f27e3b22")]
[Option('a', "key1", HelpText = "Key 1 (8 hex digits)", Required = false, Default = "f27e3b22")]
public string Key1 { get; set; } = CgssCipher.Key1.ToString("x8");

[Option('b', "key2", HelpText = "Key 2 (8 hex digits)", Required = false, DefaultValue = "00003657")]
[Option('b', "key2", HelpText = "Key 2 (8 hex digits)", Required = false, Default = "00003657")]
public string Key2 { get; set; } = CgssCipher.Key2.ToString("x8");

[Option("infinite", HelpText = "Enables infinite loop", Required = false, DefaultValue = false)]
[Option("infinite", HelpText = "Enables infinite loop", Required = false, Default = false)]
public bool InfiniteLoop { get; set; } = AudioParams.Default.InfiniteLoop;

[Option('l', "loop", HelpText = "Number of simulated loops", Required = false, DefaultValue = 0u)]
[Option('l', "loop", HelpText = "Number of simulated loops", Required = false, Default = 0u)]
public uint SimulatedLoopCount { get; set; } = AudioParams.Default.SimulatedLoopCount;

[Option('e', "no-header", HelpText = "Do not emit wave header", Required = false, DefaultValue = false)]
[Option('e', "no-header", HelpText = "Do not emit wave header", Required = false, Default = false)]
public bool NoWaveHeader { get; set; }

[Option("overrides-cipher", HelpText = "Overrides original cipher type", Required = false, DefaultValue = false)]
[Option("overrides-cipher", HelpText = "Overrides original cipher type", Required = false, Default = false)]
public bool OverridesCipherType { get; set; }

[Option('c', "cipher", HelpText = "Overridden cipher type", Required = false, DefaultValue = 0u)]
[Option('c', "cipher", HelpText = "Overridden cipher type", Required = false, Default = 0u)]
public uint OverriddenCipherType { get; set; }

}
Expand Down
31 changes: 22 additions & 9 deletions Apps/Hca2Wav/Program.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
using System;
using System.Globalization;
using System.IO;
using CommandLine;
using DereTore.Common.StarlightStage;
using DereTore.Exchange.Audio.HCA;

namespace DereTore.Apps.Hca2Wav {
internal static class Program {

private static int Main(string[] args) {
var options = new Options();
var succeeded = CommandLine.Parser.Default.ParseArguments(args, options);
const int defaultExitCodeFail = -1;

if (string.IsNullOrWhiteSpace(options.InputFileName)) {
succeeded = false;
var parser = new Parser(settings => { settings.IgnoreUnknownArguments = true; });
var parsedResult = parser.ParseArguments<Options>(args);

var succeeded = parsedResult.Tag == ParserResultType.Parsed;

Options options = null;

if (succeeded) {
options = ((Parsed<Options>)parsedResult).Value;
}

if (succeeded) {
if (string.IsNullOrWhiteSpace(options.InputFileName)) {
succeeded = false;
}
}

if (!succeeded) {
var helpText = CommandLine.Text.HelpText.AutoBuild(options);
var helpText = CommandLine.Text.HelpText.AutoBuild(parsedResult);
helpText.AddPreOptionsLine(" ");
helpText.AddPreOptionsLine("Usage: hca2wav <input HCA> [options]");
Console.Error.WriteLine(helpText);
return CommandLine.Parser.DefaultExitCodeFail;
return defaultExitCodeFail;
}

if (!File.Exists(options.InputFileName)) {
Console.Error.WriteLine("File not found: {0}", options.InputFileName);
return CommandLine.Parser.DefaultExitCodeFail;
return defaultExitCodeFail;
}

if (string.IsNullOrWhiteSpace(options.OutputFileName)) {
Expand All @@ -39,15 +52,15 @@ private static int Main(string[] args) {
if (!string.IsNullOrWhiteSpace(options.Key1)) {
if (!uint.TryParse(options.Key1, NumberStyles.HexNumber, formatProvider, out key1)) {
Console.WriteLine("ERROR: key 1 is of wrong format. It should look like \"a1b2c3d4\".");
return CommandLine.Parser.DefaultExitCodeFail;
return defaultExitCodeFail;
}
} else {
key1 = CgssCipher.Key1;
}
if (!string.IsNullOrWhiteSpace(options.Key2)) {
if (!uint.TryParse(options.Key2, NumberStyles.HexNumber, formatProvider, out key2)) {
Console.WriteLine("ERROR: key 2 is of wrong format. It should look like \"a1b2c3d4\".");
return CommandLine.Parser.DefaultExitCodeFail;
return defaultExitCodeFail;
}
} else {
key2 = CgssCipher.Key2;
Expand Down
2 changes: 1 addition & 1 deletion Apps/Hca2Wav/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineParser" version="1.9.71" targetFramework="net40" />
<package id="CommandLineParser" version="2.2.1" targetFramework="net40" />
</packages>
5 changes: 2 additions & 3 deletions Apps/JacketCreator/DereTore.Apps.JacketCreator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@
<LangVersion>6</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\..\packages\CommandLineParser.1.9.71\lib\net40\CommandLine.dll</HintPath>
<Private>True</Private>
<Reference Include="CommandLine, Version=2.2.1.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\..\packages\CommandLineParser.2.2.1\lib\net40\CommandLine.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
8 changes: 4 additions & 4 deletions Apps/JacketCreator/Options.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using CommandLine;
using CommandLine;

namespace DereTore.Apps.JacketCreator {
internal sealed class Options {

[Option("image", HelpText = "Expected image.", Required = true)]
public string ImageFileName { get; set; }

[Option("song", DefaultValue = 1001, HelpText = "The song ID. Example: 1001", Required = false)]
[Option("song", Default = 1001, HelpText = "The song ID. Example: 1001", Required = false)]
public int SongID { get; set; }

[Option('o', "output", HelpText = "The output directory of generated jacket file.", Required = true)]
public string OutputDirectory { get; set; }

[Option("path_id_m", DefaultValue = 0x547e3042158b3095, HelpText = "Path ID for medium-sized texture.", Required = false)]
[Option("path_id_m", Default = 0x547e3042158b3095, HelpText = "Path ID for medium-sized texture.", Required = false)]
public long DdsPathID { get; set; }

[Option("path_id_s", DefaultValue = unchecked((long)0xed362ad73c325b56), HelpText = "Path ID for small-sized texture.", Required = false)]
[Option("path_id_s", Default = unchecked((long)0xed362ad73c325b56), HelpText = "Path ID for small-sized texture.", Required = false)]
public long PvrPathID { get; set; }

}
Expand Down
28 changes: 18 additions & 10 deletions Apps/JacketCreator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Drawing;
using System.IO;
using CommandLine;
Expand All @@ -11,28 +11,33 @@
namespace DereTore.Apps.JacketCreator {
internal static class Program {

private static void Main(string[] args) {
var options = new Options();
var isOptionsValid = Parser.Default.ParseArguments(args, options);
private static int Main(string[] args) {
const int defaultReturnCodeFail = -1;

var parsedResult = Parser.Default.ParseArguments<Options>(args);
var isOptionsValid = parsedResult.Tag == ParserResultType.Parsed;

if (!isOptionsValid) {
var helpText = HelpText.AutoBuild(options);
HelpText.DefaultParsingErrorsHandler(options, helpText);
var helpText = HelpText.AutoBuild(parsedResult);
HelpText.DefaultParsingErrorsHandler(parsedResult, helpText);
Console.WriteLine(helpText);
return;
return defaultReturnCodeFail;
}

var options = ((Parsed<Options>)parsedResult).Value;

options.SongID = Math.Abs(options.SongID) % 10000;
if (string.IsNullOrEmpty(options.ImageFileName) && !File.Exists(options.ImageFileName)) {
Console.WriteLine($"ERROR: image file '{options.ImageFileName}' is not found.");
return;
return defaultReturnCodeFail;
}
var fullDirectoryName = (new DirectoryInfo(options.OutputDirectory)).FullName;
if (!Directory.Exists(fullDirectoryName)) {
try {
Directory.CreateDirectory(fullDirectoryName);
} catch (Exception ex) {
Console.WriteLine($"ERROR: Tried to create directory '{fullDirectoryName}' but failed.\n{ex.Message}");
return;
return defaultReturnCodeFail;
}
}

Expand All @@ -41,7 +46,7 @@ private static void Main(string[] args) {
bitmap = (Bitmap)Image.FromFile(options.ImageFileName);
} catch (Exception ex) {
Console.WriteLine($"ERROR: Cannot read image file '{options.ImageFileName}'.\n{ex.Message}");
return;
return defaultReturnCodeFail;
}

// Magic begins!
Expand All @@ -59,6 +64,7 @@ private static void Main(string[] args) {
bundleOptions.DdsImage = dds;
bundleOptions.PvrPathID = options.PvrPathID;
bundleOptions.DdsPathID = options.DdsPathID;
bundleOptions.SongID = options.SongID;

var fileName = Path.Combine(fullDirectoryName, $"jacket_{options.SongID}_android.unity3d");
using (var fileStream = File.Open(fileName, FileMode.Create, FileAccess.Write)) {
Expand All @@ -71,6 +77,8 @@ private static void Main(string[] args) {
JacketBundle.Serialize(bundleOptions, fileStream);
}
Console.WriteLine($"Building complete. Files are written to '{fullDirectoryName}', song ID = {options.SongID}.");

return 0;
}

}
Expand Down
2 changes: 1 addition & 1 deletion Apps/JacketCreator/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CommandLineParser" version="1.9.71" targetFramework="net40" />
<package id="CommandLineParser" version="2.2.1" targetFramework="net40" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="MD4.cs" />
<Compile Include="UnityEndianHelper.cs" />
<Compile Include="BundleFile.cs" />
<Compile Include="BundleFile.Initialization.cs" />
Expand Down
Loading

0 comments on commit 2a14cbc

Please sign in to comment.