Skip to content

Commit

Permalink
TDB Maker
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik-JS committed Dec 30, 2015
1 parent f8b1bf5 commit 6d38a8b
Show file tree
Hide file tree
Showing 16 changed files with 1,175 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Reads and edits game's saved data, for PC or PS3.
PS3's savedata file must be decrypted with third-party tools.
- Language: Visual Basic (.NET Framework 4.5)

## TDB Maker
Converts TDB files to and from XML.
- Language: C# (.NET Framework 4.5)

--------------------------------------------------------

### Extracting files from resource.cpk
Expand All @@ -21,8 +25,24 @@ Using [QuickBMS](http://aluigi.altervista.org/quickbms.htm):<br />
2- Select cpk.bms (available at QuickBMS' page);<br />
3- Select resource.cpk;<br />
4- Select folder where contents will be extracted to;<br />
*To avoid ambiguity: you have to enter in the folder where contents will be put.*<br />
5- Wait until everything is extracted.<br />

### Injecting modified files into resource.cpk
1- Create a 'mod' folder somewhere;<br />
2- Put edited files in the 'mod' folder, keeping the original folder hierarchy from resource.cpk;<br />
*Example: you edited or created a new TdbPauseMenu.tdb, then it should be in 'mod\resource\text'.*<br />
3- Go to QuickBMS' folder, double-click reimport.bat;<br />
4- Select cpk.bms;<br />
5- Select resource.cpk;<br />
6- Select 'mod' folder;<br />
*This means you have to enter in the 'mod' folder.*<br />
7- Wait until QuickBMS says all files have been reimported.

--------------------------------------------------------

**Always back up your files before modifying your game!**

--------------------------------------------------------

These tools are not made or supported by BANDAI NAMCO Entertainment Inc. or its affiliates.
Expand Down
67 changes: 67 additions & 0 deletions TDBMaker/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
TDB Maker
=========

This program can convert TDB files to XML, and then back to TDB, in order to facilitate
editing of the game's text.

Recommended text editor for XML editing: Notepad++ (https://notepad-plus-plus.org/)

Do not use good old Windows Notepad... more on that below.

=========================================================================================

### TDB to XML ###
------------------

- Drag and drop one or more TDB files into TDB Maker's window.
Resulting XML files will be created in the folder where source TDB's are.

OR

- Click "Convert TDB to XML";
- Select TDB file to be converted;
- Select XML file to be created.

### XML to TDB ###
------------------

- Drag and drop one or more XML files into TDB Maker's window.
Resulting TDB files will be created in the folder where source XML's are.

OR

- Click "Convert XML to TDB";
- Select XML file to be converted;
- Select TDB file to be created.

=========================================================================================

*****************
*** IMPORTANT ***
*****************

1) Do not run TDB Maker with admin rights or you may be unable to drop files on it.
This is also valid for running Visual Studio as admin and debugging TDB Maker through it.

2) Mark for new line used in generated XML's is 0A ("\n", vbLf), not 0D0A ("\r\n", vbCrLf).
Notepad can only recognize 0D0A as new line mark. Notepad++ is able to recognize both marks,
and any "enter" added by the user is written as whatever mark being already used in the file.
There are multiline strings in the game (example: Battle of Gold explanation).
TDB Maker will create a TDB file with whatever new line mark is present in the string entries
of the source XML.
While the game engine can work with both 0A and 0D0A, it seems developers intended to use only
the former. Some TDB files, which are leftovers from Brave Soldiers as far as I can tell, use
0D0A as new line mark, and TDB Maker will "convert" them to 0A (though this is useless
because, as I said, they are leftovers). BS leftovers are present in PS3 and PC versions of SS,
but only in PC they use 0D0A.

3) TDB's from BS (actual files from that game or leftovers in SS) don't have all languages
filled with text.
I originally intended to use language names in XML tags, but in order to maintain coherence
with BS, language tags in XML are named simply "LanguageX".
Language order in Brave Soldiers:
Japanese, English, Italian, French, Spanish, two unused languages and Brazilian Portuguese.
Language order in Soldiers' Soul:
Japanese, English, French, Italian, Castilian Spanish, Brazilian Portuguese, Latin American
Spanish and Chinese.

20 changes: 20 additions & 0 deletions TDBMaker/TDBMaker.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2012 for Windows Desktop
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TDBMaker", "TDBMaker\TDBMaker.csproj", "{F09BAF93-B17A-45DC-B9AC-3F443B0BB638}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F09BAF93-B17A-45DC-B9AC-3F443B0BB638}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F09BAF93-B17A-45DC-B9AC-3F443B0BB638}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F09BAF93-B17A-45DC-B9AC-3F443B0BB638}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F09BAF93-B17A-45DC-B9AC-3F443B0BB638}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions TDBMaker/TDBMaker/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
92 changes: 92 additions & 0 deletions TDBMaker/TDBMaker/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 161 additions & 0 deletions TDBMaker/TDBMaker/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TDBMaker
{
public partial class Form1 : Form
{

private static int ConversionDoneCount;
private static int IgnoreCount;

public Form1()
{
InitializeComponent();
this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
}

private void Form1_DragDrop(object sender, DragEventArgs e)
{
string[] droppedFiles = (string[])e.Data.GetData(DataFormats.FileDrop);
bool suppress = false;
if (droppedFiles.Length >= 10)
{
DialogResult dr = MessageBox.Show("You dropped " + droppedFiles.Length + " items into TDB Maker. Individual messages about overwriting and conversion result for all items will be suppressed.", "TDB Maker", MessageBoxButtons.OKCancel);
if (dr == System.Windows.Forms.DialogResult.Cancel)
return;
suppress = true;
}
ConvertItems(droppedFiles, suppress);
}

private void ConvertItems(string[] itemArray, bool suppress)
{
ConversionDoneCount = 0;
IgnoreCount = 0;
Cursor.Current = Cursors.WaitCursor;
foreach (string file in itemArray)
{
if (File.GetAttributes(file).HasFlag(FileAttributes.Directory))
{
IgnoreCount++;
if (!suppress)
MessageBox.Show(file + "\n\nThis item cannot be processed because it is a directory.");
continue;
}
string ext = Path.GetExtension(file).ToLower();
string dir = Path.GetDirectoryName(file);
string nameonly = Path.GetFileNameWithoutExtension(file);
if (ext == ".tdb")
{
ConvertToXML(file, Path.Combine(dir, nameonly + ".xml"), !suppress, suppress);
}
else if (ext == ".xml")
{
ConvertToTDB(file, Path.Combine(dir, nameonly + ".tdb"), !suppress, suppress);
}
else
{
IgnoreCount++;
if (!suppress)
MessageBox.Show(file + "\n\nThis item cannot be processed because it has no .tdb or .xml extension!");
}
}
Cursor.Current = Cursors.Default;
if (itemArray.Length <= 1)
return;
string strReport = "Item count: " + itemArray.Length + "\n";
strReport += "Conversions done: " + ConversionDoneCount + "\n";
strReport += "Conversions failed: " + (itemArray.Length - ConversionDoneCount - IgnoreCount) + "\n";
strReport += "Ignored: " + IgnoreCount;
MessageBox.Show(strReport, "Report", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
e.Effect = DragDropEffects.All;
}
}

private void btnTdb2Xml_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "TDB|*.tdb";
if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "XML|*.xml";
sfd.FileName = Path.GetFileNameWithoutExtension(ofd.FileName) + ".xml";
if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
ConvertToXML(ofd.FileName, sfd.FileName);
}

private void btnXml2Tdb_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "XML|*.xml";
if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "TDB|*.tdb";
sfd.FileName = Path.GetFileNameWithoutExtension(ofd.FileName) + ".tdb";
if (sfd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
ConvertToTDB(ofd.FileName, sfd.FileName);
}

public static void ConvertToTDB(string source, string destination, bool overwritewarning = false, bool suppressendmessage = false)
{
if (overwritewarning && File.Exists(destination))
{
DialogResult dr = MessageBox.Show(destination + "\n\nThis file is about to be overwritten. Proceed?", "Overwrite file", MessageBoxButtons.YesNo);
if (dr == DialogResult.No)
return;
}
if (TDBHandler.Xml2Tdb(source, destination))
{
if (!suppressendmessage)
MessageBox.Show("Done: " + Path.GetFileName(source) + " => " + Path.GetFileName(destination), "Xml2Tdb");
ConversionDoneCount++;
}
else
{
if (!suppressendmessage)
MessageBox.Show("Failed: " + Path.GetFileName(source) + " => " + Path.GetFileName(destination), "Xml2Tdb");
}
}

public static void ConvertToXML(string source, string destination, bool overwritewarning = false, bool suppressendmessage = false)
{
if (overwritewarning && File.Exists(destination))
{
DialogResult dr = MessageBox.Show(destination + "\n\nThis file is about to be overwritten. Proceed?", "Overwrite file", MessageBoxButtons.YesNo);
if (dr == DialogResult.No)
return;
}
if (TDBHandler.Tdb2Xml(source, destination))
{
if(!suppressendmessage)
MessageBox.Show("Done: " + Path.GetFileName(source) + " => " + Path.GetFileName(destination), "Tdb2Xml");
ConversionDoneCount++;
}
else
{
if(!suppressendmessage)
MessageBox.Show("Failed: " + Path.GetFileName(source) + " => " + Path.GetFileName(destination), "Tdb2Xml");
}
}

}
}
Loading

0 comments on commit 6d38a8b

Please sign in to comment.