Skip to content

Commit

Permalink
- Added reusable code DDCreator and DDCSettings to RocksmithToolkitLib
Browse files Browse the repository at this point in the history
- Added remastered and DD comments to Song Pack files
  • Loading branch information
cozy1 committed Dec 11, 2017
1 parent 4438942 commit 282b0ef
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 28 deletions.
Binary file modified RocksmithTookitGUI/BetaInfo.rtf
Binary file not shown.
5 changes: 3 additions & 2 deletions RocksmithTookitGUI/DDC/DDC.cs
Expand Up @@ -178,7 +178,7 @@ private void bw_DoWork(object sender, DoWorkEventArgs e)
switch (Path.GetExtension(file.Value))
{
case ".xml": // Arrangement
ApplyDD(file.Value, (int)cmbPhraseLen.Value, chkRemoveSustains.Checked, rampPath, cfgPath, out consoleOutput, chkOverwrite.Checked, chkGenLogFile.Checked);
DDCreator.ApplyDD(file.Value, (int)cmbPhraseLen.Value, chkRemoveSustains.Checked, rampPath, cfgPath, out consoleOutput, chkOverwrite.Checked, chkGenLogFile.Checked);
break;
case ".psarc": // PC / Mac (RS2014)
case ".dat": // PC (RS1)
Expand Down Expand Up @@ -209,6 +209,7 @@ private void bw_DoWork(object sender, DoWorkEventArgs e)
e.Result = errorCount; // No Errors = 0
}

[Obsolete("Depricated, please use RocksmithToolkitLib.DDCreator.", true)]
public int ApplyDD(string filePath, int phraseLen, bool removeSus, string rampPath, string cfgPath, out string consoleOutput, bool overWrite = false, bool keepLog = false)
{
var startInfo = new ProcessStartInfo
Expand Down Expand Up @@ -291,7 +292,7 @@ private int ApplyPackageDD(string filePath, int phraseLen, bool removeSus, strin
Song2014.WriteXmlComments(arr.SongXml.File, arr.XmlComments);

// apply DD to xml arrangments... 0 = Ends normally with no error
result = ApplyDD(arr.SongXml.File, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true, keepLog);
result = DDCreator.ApplyDD(arr.SongXml.File, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true, keepLog);
if (result == 1) // Ends with system error
{
consoleOutput = "DDC System Error: " + Environment.NewLine +
Expand Down
1 change: 1 addition & 0 deletions RocksmithTookitGUI/DDC/SettingsDDC.cs
Expand Up @@ -5,6 +5,7 @@

namespace RocksmithToolkitGUI.DDC
{
[Obsolete("Depricated, please use RocksmithToolkitLib.DDCSettings.", true)]
public class SettingsDDC
{
public int PhraseLen { get; private set; }
Expand Down
33 changes: 15 additions & 18 deletions RocksmithTookitGUI/DLCPackageCreator/DLCPackageCreator.cs
Expand Up @@ -1660,12 +1660,12 @@ public void btnPackageGenerate_Click(object sender = null, EventArgs e = null)

// declare one time for DDC generation
var consoleOutput = String.Empty;
SettingsDDC.Instance.LoadConfigXml();
var phraseLen = SettingsDDC.Instance.PhraseLen;
DDCSettings.Instance.LoadConfigXml();
var phraseLen = DDCSettings.Instance.PhraseLen;
// removeSus may be depricated in latest DDC but left here for comptiblity
var removeSus = SettingsDDC.Instance.RemoveSus;
var rampPath = SettingsDDC.Instance.RampPath;
var cfgPath = SettingsDDC.Instance.CfgPath;
var removeSus = DDCSettings.Instance.RemoveSus;
var rampPath = DDCSettings.Instance.RampPath;
var cfgPath = DDCSettings.Instance.CfgPath;

foreach (var arr in packageData.Arrangements)
{
Expand Down Expand Up @@ -1719,21 +1719,18 @@ public void btnPackageGenerate_Click(object sender = null, EventArgs e = null)
// Important ... don't overwrite author's DD if it is already present in any arragement
if (!isDD)
{
using (var ddc = new DDC.DDC())
// apply DD to xml arrangments
var result = DDCreator.ApplyDD(arr.SongXml.File, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true);
if (result == 1)
{
// apply DD to xml arrangments
var singleResult = ddc.ApplyDD(arr.SongXml.File, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true);
if (singleResult == 1)
{
var errMsg = "DDC generated an error while processing arrangement:" + Environment.NewLine + arr.SongXml.File + Environment.NewLine;
BetterDialog2.ShowDialog(errMsg, "DDC Generated Error", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
}
var errMsg = "DDC generated an error while processing arrangement:" + Environment.NewLine + arr.SongXml.File + Environment.NewLine;
BetterDialog2.ShowDialog(errMsg, "DDC Generated Error", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
}

if (singleResult == 2)
{
consoleOutput = String.Format("Arrangement file '{0}' => {1}", Path.GetFileNameWithoutExtension(arr.SongXml.File), consoleOutput);
BetterDialog2.ShowDialog(consoleOutput, "DDC Generation Info", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
}
if (result == 2)
{
consoleOutput = String.Format("Arrangement file '{0}' => {1}", Path.GetFileNameWithoutExtension(arr.SongXml.File), consoleOutput);
BetterDialog2.ShowDialog(consoleOutput, "DDC Generation Info", null, null, "Ok", Bitmap.FromHicon(SystemIcons.Error.Handle), "Error", 150, 150);
}
}
else
Expand Down
5 changes: 3 additions & 2 deletions RocksmithTookitGUI/DLCPackerUnpacker/DLCPackerUnpacker.cs
Expand Up @@ -231,8 +231,9 @@ private void UnpackSongs(IEnumerable<string> sourceFileNames, string destPath, b
packageCreator.CurrentGameVersion = platform.version;
//packageCreator.SelectComboAppId(info.AppId);
packageCreator.AppId = info.AppId;
// save template xml file
packageCreator.SaveTemplateFile(unpackedDir, false);
// save template xml file except when SongPack
if (!sourceFileName.Contains("_sp_") && !sourceFileName.Contains("_songpack_"))
packageCreator.SaveTemplateFile(unpackedDir, false);
}
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion RocksmithTookitGUI/Properties/AssemblyInfo.cs
Expand Up @@ -29,6 +29,6 @@
//
// THESE VALUES ARE PROGRAMMATICALLY GENERATED - DO NOT EDIT
[assembly: AssemblyVersion("2.8.4.1")]
[assembly: AssemblyInformationalVersion("1df2e6f9")]
[assembly: AssemblyInformationalVersion("4438942a")]
[assembly: AssemblyConfiguration("BETA")]
[assembly: NeutralResourcesLanguageAttribute("en")]
Expand Up @@ -7,6 +7,10 @@
using Newtonsoft.Json.Linq;
using RocksmithToolkitLib.Extensions;
using RocksmithToolkitLib.Properties;
using RocksmithToolkitLib.XML;
using System.Diagnostics;
using RocksmithToolkitLib.DLCPackage.Manifest.Functions;
using RocksmithToolkitLib.XmlRepository;

namespace RocksmithToolkitLib.DLCPackage.AggregateGraph2014
{
Expand Down Expand Up @@ -626,9 +630,55 @@ public static string DoLikeSongPack(string srcPath, string appId = "248750")
foreach (var sng in sngFiles)
File.Copy(sng, Path.Combine(binGenericDir, Path.GetFileName(sng)));

// declare variables one time for use in DDC generation
DDCSettings.Instance.LoadConfigXml();
var phraseLen = DDCSettings.Instance.PhraseLen;
// removeSus may be depricated in latest DDC but left here for comptiblity
var removeSus = DDCSettings.Instance.RemoveSus;
var rampPath = DDCSettings.Instance.RampPath;
var cfgPath = DDCSettings.Instance.CfgPath;

// generate SongPack comment
var spComment = "(Remastered by SongPack Maker)";
var addDD = false;
if (ConfigRepository.Instance().GetBoolean("ddc_autogen"))
{
addDD = true;
spComment += " " + "(DDC by SongPack Maker)";
}

var xmlFiles = Directory.EnumerateFiles(srcPath, "*.xml", SearchOption.AllDirectories).ToArray();
foreach (var xml in xmlFiles)
File.Copy(xml, Path.Combine(songsArrDir, Path.GetFileName(xml)));
{
// completely skip dlc.xml template files
if (xml.EndsWith("_RS2014.dlc.xml"))
continue;

var xmlSongPack = Path.Combine(songsArrDir, Path.GetFileName(xml));
File.Copy(xml, xmlSongPack);

// skip vocal and showlight xml files
if (xml.EndsWith("_vocals.xml") || xml.EndsWith("_showlights.xml"))
continue;

// add DDC to xml arrangement
if (addDD)
{
// check if arrangment has pre existing DD and do not overwrite
var songXml = Song2014.LoadFromFile(xml);
var mf = new ManifestFunctions(GameVersion.RS2014);
if (mf.GetMaxDifficulty(songXml) == 0)
{
var consoleOutput = String.Empty;
// apply DD to xml arrangments... 0 = Ends normally with no error
var result = DDCreator.ApplyDD(xmlSongPack, phraseLen, removeSus, rampPath, cfgPath, out consoleOutput, true);
if (result == 1)
Debug.WriteLine(String.Format("Arrangement file '{0}' => {1}", Path.GetFileNameWithoutExtension(xml), "DDC ended with system error " + consoleOutput));
else if (result == 2)
Debug.WriteLine(String.Format("Arrangement file '{0}' => {1}", Path.GetFileNameWithoutExtension(xml), "DDC ended with application error " + consoleOutput));
}
}
}

// generate new Aggregate Graph
var aggGraphPack = new AggregateGraph2014();
Expand Down Expand Up @@ -699,7 +749,7 @@ public static string DoLikeSongPack(string srcPath, string appId = "248750")
using (var fs = new FileStream(toolkitVersionFile, FileMode.Create))
using (var ms = new MemoryStream())
{
DLCPackageCreator.GenerateToolkitVersion(ms, packageComment: "SongPack Maker v1.1");
DLCPackageCreator.GenerateToolkitVersion(ms, packageVersion: "SongPack Maker v1.2", packageComment: spComment);
ms.Flush();
ms.Seek(0, SeekOrigin.Begin);
ms.CopyTo(fs);
Expand Down
91 changes: 91 additions & 0 deletions RocksmithToolkitLib/DLCPackage/DDCreator.cs
@@ -0,0 +1,91 @@
using System;
using System.Diagnostics;
using System.IO;
using RocksmithToolkitLib.XmlRepository;

namespace RocksmithToolkitLib.DLCPackage
{
public static class DDCreator
{
internal static string AppDir = AppDomain.CurrentDomain.BaseDirectory;
internal static string DdcDir = Path.Combine(AppDir, "ddc");

/// <summary>
/// Apply Dynamic Difficulty (DD) to an arrangement xml file
/// </summary>
/// <param name="filePath"></param>
/// <param name="phraseLen"></param>
/// <param name="removeSus"></param>
/// <param name="rampPath"></param>
/// <param name="cfgPath"></param>
/// <param name="consoleOutput"></param>
/// <param name="overWrite"></param>
/// <param name="keepLog"></param>
/// <returns>0 => ends normally, 1 => ends with system error, 2 => ends with application error</returns>
public static int ApplyDD(string filePath, int phraseLen, bool removeSus, string rampPath, string cfgPath, out string consoleOutput, bool overWrite = false, bool keepLog = false)
{
var startInfo = new ProcessStartInfo
{
FileName = Path.Combine(DdcDir, "ddc.exe"),
WorkingDirectory = Path.GetDirectoryName(filePath),
Arguments = String.Format("\"{0}\" -l {1} -s {2} -m \"{3}\" -c \"{4}\" -p {5} -t {6}",
Path.GetFileName(filePath), (UInt16)phraseLen, removeSus ? "Y" : "N",
rampPath, cfgPath, overWrite ? "Y" : "N", keepLog ? "Y" : "N"
),
UseShellExecute = false,
CreateNoWindow = true, // hide command window
RedirectStandardOutput = true,
RedirectStandardError = true
};

using (var DDC = new Process())
{
DDC.StartInfo = startInfo;
DDC.Start();
consoleOutput = DDC.StandardOutput.ReadToEnd();
consoleOutput += DDC.StandardError.ReadToEnd();
DDC.WaitForExit(1000 * 60 * 15); //wait for 15 minutes, crunchy solution for AV-sandboxing issues
return DDC.ExitCode;
}
}
}

public class DDCSettings
{
public int PhraseLen { get; private set; }
public bool RemoveSus { get; private set; }
public string RampPath { get; private set; }
public string CfgPath { get; private set; }

private static DDCSettings _instance;
public static DDCSettings Instance
{
get
{
if (_instance == null)
_instance = new DDCSettings();
return _instance;
}
}

public void LoadConfigXml()
{
var baseDir = AppDomain.CurrentDomain.BaseDirectory;
var ddcDir = Path.Combine(baseDir, "ddc");
var configFile = ConfigRepository.Instance()["ddc_config"] + ".cfg";
var rampupFile = ConfigRepository.Instance()["ddc_rampup"] + ".xml";

PhraseLen = (int)ConfigRepository.Instance().GetDecimal("ddc_phraselength");
RemoveSus = ConfigRepository.Instance().GetBoolean("ddc_removesustain");
RampPath = Path.Combine(ddcDir, rampupFile);
CfgPath = Path.Combine(ddcDir, configFile);

if (!File.Exists(RampPath) || !File.Exists(CfgPath))
throw new FileNotFoundException("DDC support files are missing");

// // -m "D:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\rocksmith-custom-song-toolkit\RocksmithTookitGUI\bin\Debug\ddc\ddc_default.xml"
// // -c "D:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\rocksmith-custom-song-toolkit\RocksmithTookitGUI\bin\Debug\ddc\ddc_default.cfg"
}
}

}
2 changes: 1 addition & 1 deletion RocksmithToolkitLib/Properties/AssemblyInfo.cs
Expand Up @@ -27,6 +27,6 @@
//
// THESE VALUES ARE PROGRAMMATICALLY GENERATED - DO NOT EDIT
[assembly: AssemblyVersion("2.8.4.1")]
[assembly: AssemblyInformationalVersion("1df2e6f9")]
[assembly: AssemblyInformationalVersion("4438942a")]
[assembly: AssemblyConfiguration("BETA")]
[assembly: NeutralResourcesLanguageAttribute("en")]
1 change: 1 addition & 0 deletions RocksmithToolkitLib/RocksmithToolkitLib.csproj
Expand Up @@ -61,6 +61,7 @@
<ItemGroup>
<Compile Include="Conversion\Rs1Converter.cs" />
<Compile Include="Conversion\Rs2014Converter.cs" />
<Compile Include="DLCPackage\DDCreator.cs" />
<Compile Include="SngToTab\Common.cs" />
<Compile Include="SngToTab\Sng2Tab.cs" />
<Compile Include="SngToTab\TabBeat.cs" />
Expand Down
2 changes: 1 addition & 1 deletion RocksmithToolkitUpdater/Properties/AssemblyInfo.cs
Expand Up @@ -29,6 +29,6 @@
//
// THESE VALUES ARE PROGRAMMATICALLY GENERATED - DO NOT EDIT
[assembly: AssemblyVersion("2.8.4.1")]
[assembly: AssemblyInformationalVersion("1df2e6f9")]
[assembly: AssemblyInformationalVersion("4438942a")]
[assembly: AssemblyConfiguration("BETA")]
[assembly: NeutralResourcesLanguageAttribute("en")]
2 changes: 1 addition & 1 deletion VersionInfo.txt
@@ -1,3 +1,3 @@
2.8.4.1
1df2e6f9
4438942a
BETA

0 comments on commit 282b0ef

Please sign in to comment.