Skip to content

Commit

Permalink
~Finally corrected the label renaming bugs.
Browse files Browse the repository at this point in the history
~Modified the LBL1 loading routine to patch broken labels in files when they're opened.
  • Loading branch information
IcySon55 committed Oct 6, 2016
1 parent b61d7d6 commit 50365a6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion App.config
Expand Up @@ -48,7 +48,7 @@
<applicationSettings>
<MsbtEditor.Properties.Settings>
<setting name="ApplicationName" serializeAs="String">
<value>MSBT Editor Reloaded v0.9.6</value>
<value>MSBT Editor Reloaded v0.9.7</value>
</setting>
</MsbtEditor.Properties.Settings>
</applicationSettings>
Expand Down
22 changes: 22 additions & 0 deletions MSBT.cs
Expand Up @@ -318,6 +318,19 @@ private void ReadLBL1(BinaryReaderX br)
}
}

// Old rename correction
foreach (Label lbl in LBL1.Labels)
{
uint previousChecksum = lbl.Checksum;
lbl.Checksum = LabelChecksum(lbl.Name);

if (previousChecksum != lbl.Checksum)
{
LBL1.Groups[(int)previousChecksum].NumberOfLabels -= 1;
LBL1.Groups[(int)lbl.Checksum].NumberOfLabels += 1;
}
}

if (LBL1.Labels.Count > 0)
HasLabels = true;

Expand Down Expand Up @@ -452,6 +465,15 @@ public Label AddLabel(string name)
return nlbl;
}

public void RenameLabel(Label lbl, string newName)
{
lbl.Length = (uint)Encoding.ASCII.GetBytes(newName.Trim()).Length;
lbl.Name = newName.Trim();
LBL1.Groups[(int)lbl.Checksum].NumberOfLabels -= 1;
lbl.Checksum = LabelChecksum(newName.Trim());
LBL1.Groups[(int)lbl.Checksum].NumberOfLabels += 1;
}

public void RemoveLabel(Label lbl)
{
int textIndex = TXT2.Strings.IndexOf(lbl.String);
Expand Down
2 changes: 1 addition & 1 deletion Properties/AssemblyInfo.cs
Expand Up @@ -31,4 +31,4 @@
//
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// usando l'asterisco '*' come illustrato di seguito:
[assembly: AssemblyVersion("0.9.6.0")]
[assembly: AssemblyVersion("0.9.7.0")]
2 changes: 1 addition & 1 deletion Properties/Settings.Designer.cs

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

2 changes: 1 addition & 1 deletion Properties/Settings.settings
Expand Up @@ -6,7 +6,7 @@
<Value Profile="(Default)" />
</Setting>
<Setting Name="ApplicationName" Type="System.String" Scope="Application">
<Value Profile="(Default)">MSBT Editor Reloaded v0.9.6</Value>
<Value Profile="(Default)">MSBT Editor Reloaded v0.9.7</Value>
</Setting>
<Setting Name="BG4OpenDirectory" Type="System.String" Scope="User">
<Value Profile="(Default)" />
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -38,6 +38,8 @@ I creataed this editor a while ago to support a translation project I was planni
* BG4 Extraction - Extract files from within BG4 archives found in games like Mario & Luigi Paper Jam.
* LZ11 De/Compression - Compress and Decompress files using LZ11. Held onto this feature from Exelix11's original version.
* UMSBT Extraction & Packing - Extract MSBT files from UMSBT archives and repack them into UMSBT archives.
* v0.9.7 will correct broken files that were previously broken by v0.9.6 and below. Just open the broken file and then click save to fix it.

### Known Issues
* v0.8.6 - LZ11 Compression windows do not appear. Update to v0.9.0+.
* v0.9.6 and below - Label renaming is broken. Update to v0.9.7+.
4 changes: 1 addition & 3 deletions frmMain.cs
Expand Up @@ -766,9 +766,7 @@ private void btnSaveLabel_Click(object sender, EventArgs e)

if (!taken)
{
Label lbl = (Label)lstStrings.SelectedItem;
lbl.Length = (uint)Encoding.ASCII.GetBytes(txtLabelName.Text.Trim()).Length;
lbl.Name = txtLabelName.Text.Trim();
_msbt.RenameLabel((Label)lstStrings.SelectedItem, txtLabelName.Text.Trim());
int selectedIndex = lstStrings.SelectedIndex;
LoadFile();
if (lstStrings.Items.Count > selectedIndex)
Expand Down

0 comments on commit 50365a6

Please sign in to comment.