Skip to content

Commit

Permalink
Fixed: illegal chars in vocals, converter
Browse files Browse the repository at this point in the history
*TranscriptionTrack base class added.
*Contributing. IDE coe formatting suggestion.
*HSL>cs modded.
*Not that stable, beware of hidden bugs.
  • Loading branch information
L0FKA committed Dec 20, 2014
1 parent 26f0c30 commit ecc84d0
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 414 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -32,3 +32,7 @@
* While the issue should have details about what you're doing, make your commit message meaningful rather than something like "Fixes #1234"
* A good commit message might be something like `Adds support for Drop D tuning (#1234)`
* Submit a [pull request](https://help.github.com/articles/using-pull-requests) to the rscustom repository.

## Code Style

* Use spaces for indentation, and Windows line endings, enable unprintable symbols to make sure that you're doing fine.
29 changes: 15 additions & 14 deletions RocksmithSngHSL/Rocksmith2014Sng2cs.rb
Expand Up @@ -26,6 +26,7 @@ def t(lvl=0)
// AUTO-GENERATED FILE, DO NOT MODIFY!
using System;
using System.IO;
using MiscUtil.IO;
namespace RocksmithToolkitLib.Sng2014HSL {
EOF
Expand Down Expand Up @@ -60,50 +61,50 @@ def t(lvl=0)
l = "#{t(2)}public #{type} #{$3} { get; set; }"
name = get_name($3)
order << name
reader << "this.#{name}.read(r);"
reader << "#{name}.read(r);"
# need to construct object too
# will be rewritten for arrays
reader[-1] = "this.#{name} = new #{type}(); " + reader[-1];
reader[-1] = "#{name} = new #{type}(); " + reader[-1];
#common types
elsif l =~ /^(.+)ulong (.*);/
l = "#{t(2)}public UInt32 #{$2} { get; set; }"
name = get_name($2)
order << name
reader << "this.#{name} = r.ReadUInt32();"
reader << "#{name} = r.ReadUInt32();"
elsif l =~ /^(.+)long (.*);/
l = "#{t(2)}public Int32 #{$2} { get; set; }"
name = get_name($2)
order << name
reader << "this.#{name} = r.ReadInt32();"
reader << "#{name} = r.ReadInt32();"
elsif l =~ /^(.+)short (.*);/
l = "#{t(2)}public Int16 #{$2} { get; set; }"
name = get_name($2)
order << name
reader << "this.#{name} = r.ReadInt16();"
reader << "#{name} = r.ReadInt16();"
elsif l =~ /^(.+)char (.*);/ || l =~ /^(.+)byte (.*);/
l = "#{t(2)}public Byte #{$2} { get; set; }"
name = get_name($2)
order << name
reader << "this.#{name} = r.ReadByte();"
reader << "#{name} = r.ReadByte();"
elsif l =~ /^(.+)float (.*);/
l = "#{t(2)}public float #{$2} { get; set; }"
name = get_name($2)
order << name
reader << "this.#{name} = r.ReadSingle();"
reader << "#{name} = r.ReadSingle();"
elsif l =~ /^(.+)double (.*);/
l = "#{t(2)}public double #{$2} { get; set; }"
name = get_name($2)
order << name
reader << "this.#{name} = r.ReadDouble();"
reader << "#{name} = r.ReadDouble();"
elsif l =~ /^(\s+)(.+) (.*);/
throw "Unhandled type: #{$2}"
end

if l =~ /^};$/ #order[]
list = order.map { |name| "\t\"#{name}\"" }.join(','+ind)
puts "#{ind}public string[] _order = {#{ind}#{list}#{ind}};"
puts "\t\tpublic string[] order { get { return this._order; } }"
puts "#{t(2)}public void read(BinaryReader r) {#{n(3)}#{reader.join(n(3))}#{ind}}"
puts "\t\tpublic string[] order { get { return _order; } }"
puts "#{t(2)}public void read(EndianBinaryReader r) {#{n(3)}#{reader.join(n(3))}#{ind}}"
puts "\t}\n"
order = []
reader = []
Expand All @@ -115,17 +116,17 @@ def t(lvl=0)
prefix = "this."
if count =~ /^[0-9]+$/
l = "#{ws}public #{type}[] _#{name} = new #{type}[#{count}];\n"
l << "#{ws}public #{type}[] #{name} { get { return this._#{name}; } set { _#{name} = value; } }"
l << "#{ws}public #{type}[] #{name} { get { return _#{name}; } set { _#{name} = value; } }"
prefix = ''
else
l = "#{ws}public #{type}[] #{name}#{rest}"
end
if type == 'Byte'
reader[-1] = "this.#{name} = r.ReadBytes(#{count});"
reader[-1] = "#{name} = r.ReadBytes(#{count});"
elsif readfn.include? type
reader[-1] = "this.#{name} = new #{type}[#{prefix}#{count}]; for (int i=0; i<#{prefix}#{count}; i++) this.#{name}[i] = #{readfn[type]};"
reader[-1] = "#{name} = new #{type}[#{count}]; for (int i = 0; i < #{count}; i++) #{name}[i] = #{readfn[type]};"
else
reader[-1] = "this.#{name} = new #{type}[#{prefix}#{count}]; for (int i=0; i<#{prefix}#{count}; i++) { #{type} obj = new #{type}(); obj.read(r); this.#{name}[i] = obj; }"
reader[-1] = "#{name} = new #{type}[#{count}]; for (int i = 0; i < #{count}; i++) { var obj = new #{type}(); obj.read(r); #{name}[i] = obj; }"
end
end
puts l if l
Expand Down
10 changes: 7 additions & 3 deletions RocksmithTookitGUI/DLCPackageCreator/DLCPackageCreator.cs
Expand Up @@ -560,6 +560,9 @@ public void loadTemplate(string dlcLoadPath)
var packagePlatform = sourcePackage.GetPlatform();
var unpackedDir = Packer.Unpack(sourcePackage, tmp, true, true, false);
savePath = Path.Combine(savePath, Path.GetFileNameWithoutExtension(sourcePackage));
// Same name xbox issue fix
if(packagePlatform.platform == GamePlatform.XBox360)
savePath += GamePlatform.XBox360.ToString();
DirectoryExtension.Move(unpackedDir, savePath, true);
unpackedDir = savePath;

Expand All @@ -569,7 +572,7 @@ public void loadTemplate(string dlcLoadPath)
unpackedDir = DLCPackageData.DoLikeProject(savePath);

// LOAD DATA
var info = DLCPackageData.LoadFromFolder(unpackedDir, packagePlatform);
var info = DLCPackageData.LoadFromFolder(unpackedDir, packagePlatform, packagePlatform);

switch (packagePlatform.platform)
{
Expand Down Expand Up @@ -828,7 +831,8 @@ public void ApplyBassFix(Arrangement arr)
Application.DoEvents();
AppIdTB.Text = info.AppId;
SelectComboAppId(info.AppId);

if (AppIdTB.Text == "")
AppIdTB.Text = "248750"; //hardcoded for now
AlbumTB.Text = info.SongInfo.Album;
SongDisplayNameTB.Text = info.SongInfo.SongDisplayName;
SongDisplayNameSortTB.Text = info.SongInfo.SongDisplayNameSort;
Expand Down Expand Up @@ -1415,7 +1419,7 @@ private void plataform_CheckedChanged(object sender, EventArgs e)
}

private void SelectComboAppId(string appId) {
SongAppId songAppId = SongAppIdRepository.Instance().Select(appId, CurrentGameVersion);
var songAppId = SongAppIdRepository.Instance().Select(appId, CurrentGameVersion);
if (SongAppIdRepository.Instance().List.Any<SongAppId>(a => a.AppId == appId))
cmbAppIds.SelectedItem = songAppId;
}
Expand Down
6 changes: 3 additions & 3 deletions RocksmithToolkitLib/DLCPackage/DLCPackageConverter.cs
Expand Up @@ -39,7 +39,7 @@ public static class DLCPackageConverter

// CONVERSION
if (needRebuildPackage)
ConvertPackageRebuilding(unpackedDir, targetFileName, targetPlatform, appId);
ConvertPackageRebuilding(unpackedDir, targetFileName, sourcePlatform, targetPlatform, appId);
else
ConvertPackageForSimilarPlatform(unpackedDir, targetFileName, sourcePlatform, targetPlatform, appId);

Expand Down Expand Up @@ -102,9 +102,9 @@ private static void ConvertPackageForSimilarPlatform(string unpackedDir, string
DirectoryExtension.SafeDelete(unpackedDir);
}

private static void ConvertPackageRebuilding(string unpackedDir, string targetFileName, Platform targetPlatform, string appId)
private static void ConvertPackageRebuilding(string unpackedDir, string targetFileName, Platform sourcePlatform, Platform targetPlatform, string appId)
{
var data = DLCPackageData.LoadFromFolder(unpackedDir, targetPlatform);
var data = DLCPackageData.LoadFromFolder(unpackedDir, targetPlatform, sourcePlatform);
// Update AppID
if (!targetPlatform.IsConsole)
data.AppId = appId;
Expand Down
40 changes: 21 additions & 19 deletions RocksmithToolkitLib/DLCPackage/DLCPackageData.cs
Expand Up @@ -72,33 +72,18 @@ public List<XBox360License> XBox360Licenses
/// <returns>The DLCPackageData info.</returns>
/// <param name="unpackedDir">Unpacked dir.</param>
/// <param name="targetPlatform">Target platform.</param>
public static DLCPackageData LoadFromFolder(string unpackedDir, Platform targetPlatform) {
/// <param name = "sourcePlatform"></param>
public static DLCPackageData LoadFromFolder(string unpackedDir, Platform targetPlatform, Platform sourcePlatform = null) {
var data = new DLCPackageData();
data.GameVersion = GameVersion.RS2014;
data.SignatureType = PackageMagic.CON;
if (sourcePlatform == null)
sourcePlatform = unpackedDir.GetPlatform();

//Arrangements / Tones
data.Arrangements = new List<Arrangement>();
data.TonesRS2014 = new List<Tone2014>();

//Source platform + audio files
var targetAudioFiles = new List<string>();
var sourceAudioFiles = Directory.GetFiles(unpackedDir, "*.wem", SearchOption.AllDirectories);
Platform sourcePlatform = new Platform(GamePlatform.Pc, GameVersion.None);

foreach (var file in sourceAudioFiles) {
var newFile = Path.Combine(Path.GetDirectoryName(file), String.Format("{0}_fixed{1}", Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)));
if (targetPlatform.IsConsole != (sourcePlatform = file.GetAudioPlatform()).IsConsole)
{
OggFile.ConvertAudioPlatform(file, newFile);
targetAudioFiles.Add(newFile);
}
else targetAudioFiles.Add(file);
}

if (!targetAudioFiles.Any())
throw new InvalidDataException("Audio files not found.");

//Load files
var jsonFiles = Directory.GetFiles(unpackedDir, "*.json", SearchOption.AllDirectories);
foreach (var json in jsonFiles) {
Expand Down Expand Up @@ -182,6 +167,23 @@ public List<XBox360License> XBox360Licenses
data.LyricArtPath = LyricArt[0];

//Get other files
//Audio files
var targetAudioFiles = new List<string>();
var sourceAudioFiles = Directory.GetFiles(unpackedDir, "*.wem", SearchOption.AllDirectories).ToArray();

foreach (var file in sourceAudioFiles) {
var newFile = Path.Combine(Path.GetDirectoryName(file), String.Format("{0}_fixed{1}", Path.GetFileNameWithoutExtension(file), Path.GetExtension(file)));
if (targetPlatform.IsConsole != (sourcePlatform = file.GetAudioPlatform()).IsConsole)
{
OggFile.ConvertAudioPlatform(file, newFile);
targetAudioFiles.Add(newFile);
}
else targetAudioFiles.Add(file);
}

if (!targetAudioFiles.Any())
throw new InvalidDataException("Audio files not found.");

string audioPath = null, audioPreviewPath = null;
FileInfo a = new FileInfo(targetAudioFiles[0]);
FileInfo b = null;
Expand Down
9 changes: 5 additions & 4 deletions RocksmithToolkitLib/DLCPackage/Packer.cs
Expand Up @@ -64,10 +64,14 @@ public static void Pack(string sourcePath, string saveFileName, bool updateSng =
public static string Unpack(string sourceFileName, string savePath, bool decodeAudio = false, bool extractSongXml = false, bool overwriteSongXml = true, Platform predefinedPlatform = null)
{
Platform platform = sourceFileName.GetPlatform();

if (predefinedPlatform != null && predefinedPlatform.platform != GamePlatform.None && predefinedPlatform.version != GameVersion.None)
platform = predefinedPlatform;

var fnameWithoutExt = Path.GetFileNameWithoutExtension(sourceFileName);
var unpackedDir = Path.Combine(savePath, String.Format("{0}_{1}", fnameWithoutExt, platform.platform));
if (Directory.Exists(unpackedDir))
DirectoryExtension.SafeDelete(unpackedDir);

var useCryptography = platform.version == GameVersion.RS2012; // Cryptography way is used only for PC in Rocksmith 1
switch (platform.platform)
{
Expand Down Expand Up @@ -100,12 +104,9 @@ public static string Unpack(string sourceFileName, string savePath, bool decodeA
throw new InvalidOperationException("Platform not found :(");
}

var fnameWithoutExt = Path.GetFileNameWithoutExtension(sourceFileName);
if (platform.platform == GamePlatform.PS3)
fnameWithoutExt = fnameWithoutExt.Substring(0, fnameWithoutExt.LastIndexOf("."));

var unpackedDir = Path.Combine(savePath, String.Format("{0}_{1}", fnameWithoutExt, platform.platform));

// DECODE AUDIO
if (decodeAudio) {
var audioFiles = Directory.GetFiles(unpackedDir, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".ogg") || s.EndsWith(".wem"));
Expand Down
8 changes: 4 additions & 4 deletions RocksmithToolkitLib/DLCPackage/RijndaelEncryptor.cs
Expand Up @@ -347,7 +347,7 @@ internal static bool IfJavaInstalled()
public static string EncryptPS3Edat()
{
if(!IfJavaInstalled())
return "No JDK or JRE is intsalled on your machine";
return "No JDK or JRE is installed on your machine";

string errors = string.Empty;
var files = Directory.EnumerateFiles(Path.Combine(toolkitPath, "edat"), "*.psarc");
Expand All @@ -368,7 +368,7 @@ public static string EncryptPS3Edat()
public static string DecryptPS3Edat()
{
if(!IfJavaInstalled())
return "No JDK or JRE is intsalled on your machine";
return "No JDK or JRE is installed on your machine";

string errors = string.Empty;
var files = Directory.EnumerateFiles(Path.Combine(toolkitPath, "edat"), "*.edat");
Expand Down Expand Up @@ -399,9 +399,9 @@ internal static string EdatCrypto(string command)
PS3Process.WaitForExit();

string stdout = PS3Process.StandardError.ReadToEnd();
//Improove me please
//Improve me please
if (!String.IsNullOrEmpty(stdout))
return String.Format("System error occured {0}\n", stdout);
return String.Format("System error occurred {0}\n", stdout);
return "";
}

Expand Down
24 changes: 10 additions & 14 deletions RocksmithToolkitLib/Extensions/FileStreamExtension.cs
Expand Up @@ -8,7 +8,7 @@ namespace RocksmithToolkitLib.Extensions
{
public class TempFileStream : FileStream
{
static int _buffer_size = 65536;
const int _buffer_size = 65536;
public TempFileStream()
: base(Path.GetTempFileName(), FileMode.Create, FileAccess.ReadWrite, FileShare.Read, _buffer_size, FileOptions.DeleteOnClose) { }

Expand All @@ -24,37 +24,33 @@ public TempFileStream(FileAccess access, FileShare share, int bufferSize)

public class XmlStreamingDeserializer<T>
{
static XmlSerializerNamespaces _ns;
XmlSerializer _serializer = new XmlSerializer(typeof(T));
//XmlSerializerNamespaces _ns;
XmlSerializer _serializer;
XmlReader _reader;

static XmlStreamingDeserializer()
{
_ns = new XmlSerializerNamespaces();
_ns.Add("", "");
}

private XmlStreamingDeserializer()
public XmlStreamingDeserializer()
{
//_ns = new XmlSerializerNamespaces();
//_ns.Add("", "");
_serializer = new XmlSerializer(typeof(T));
}

public XmlStreamingDeserializer(TextReader reader)
: this(XmlReader.Create(reader))
{
}

public XmlStreamingDeserializer(XmlReader reader)
: this()
{
_reader = reader;
}

public void Close()
{
_reader.Close();
}

public T Deserialize()
{
while (_reader.IsStartElement())
Expand Down
14 changes: 14 additions & 0 deletions RocksmithToolkitLib/Extensions/GeneralExtension.cs
Expand Up @@ -101,6 +101,20 @@ public static DLCPackage.ToolkitInfo GetToolkitInfo(StreamReader reader)
return info;
}

/// <summary>
/// Strips non-printable ASCII characters
/// </summary>
/// <param name="filePath">Full path to the File</param>
public static Stream StripIllegalXMLChars(this string filePath)
{
string tmpContents = File.ReadAllText(filePath);
string pattern = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]";

tmpContents = Regex.Replace(tmpContents, pattern, "", RegexOptions.IgnoreCase);

return new MemoryStream(new UTF8Encoding(false).GetBytes(tmpContents));
}

public static string GetValidVersion(this string value)
{
if (!String.IsNullOrEmpty(value))
Expand Down

0 comments on commit ecc84d0

Please sign in to comment.