mirror of
https://github.com/chev2/botw-toolset.git
synced 2025-12-19 14:33:16 +00:00
Update TSCB methods
FromBytes replaces ReadFile & uses a byte array instead of filename. GetBytes is renamed to ToBytes.
This commit is contained in:
parent
6d6e9f4749
commit
f19f94f459
2 changed files with 132 additions and 139 deletions
|
|
@ -306,7 +306,7 @@ namespace BOTWToolset.Control
|
||||||
|
|
||||||
BOTWConsole.Log("Opening file");
|
BOTWConsole.Log("Opening file");
|
||||||
|
|
||||||
TSCB t = TSCB.ReadFile(openFileDialog.FileName);
|
TSCB t = TSCB.FromBytes(File.ReadAllBytes(openFileDialog.FileName));
|
||||||
|
|
||||||
// Set the current file location to the chosen file's location
|
// Set the current file location to the chosen file's location
|
||||||
fileLocation = openFileDialog.FileName;
|
fileLocation = openFileDialog.FileName;
|
||||||
|
|
@ -365,7 +365,7 @@ namespace BOTWToolset.Control
|
||||||
|
|
||||||
if ((bool)saveFileDialog.ShowDialog())
|
if ((bool)saveFileDialog.ShowDialog())
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(saveFileDialog.FileName, TSCB.GetBytes(currentTSCB));
|
File.WriteAllBytes(saveFileDialog.FileName, TSCB.ToBytes(currentTSCB));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -52,14 +52,12 @@ namespace BOTWToolset.IO.TSCB
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="file">The .tscb file.</param>
|
/// <param name="file">The .tscb file.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static TSCB ReadFile(string file)
|
public static TSCB FromBytes(byte[] bytes)
|
||||||
{
|
|
||||||
if (File.Exists(file))
|
|
||||||
{
|
{
|
||||||
TSCB t = new TSCB();
|
TSCB t = new TSCB();
|
||||||
|
|
||||||
// Use big-endian
|
// Use big-endian
|
||||||
using (var r = new BinaryReaderBig(File.Open(file, FileMode.Open)))
|
using (var r = new BinaryReaderBig(new MemoryStream(bytes)))
|
||||||
{
|
{
|
||||||
// Set header info from file on the new TSCBInfo
|
// Set header info from file on the new TSCBInfo
|
||||||
t.Signature = new string(r.ReadChars(4));
|
t.Signature = new string(r.ReadChars(4));
|
||||||
|
|
@ -174,8 +172,8 @@ namespace BOTWToolset.IO.TSCB
|
||||||
}
|
}
|
||||||
else //If the length is 4
|
else //If the length is 4
|
||||||
{
|
{
|
||||||
var bytes = r.ReadBytes(16).ToArray();
|
var areabytes = r.ReadBytes(16).ToArray();
|
||||||
if (bytes[7] == 0) //If byte 7 equals 0
|
if (areabytes[7] == 0) //If byte 7 equals 0
|
||||||
areaInfo.HasGrass = true;
|
areaInfo.HasGrass = true;
|
||||||
else //Else if the 2nd byte should be anything else (should always be 1)
|
else //Else if the 2nd byte should be anything else (should always be 1)
|
||||||
areaInfo.HasWater = true;
|
areaInfo.HasWater = true;
|
||||||
|
|
@ -210,18 +208,13 @@ namespace BOTWToolset.IO.TSCB
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new FileNotFoundException("Cannot find .tscb file to read.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes TSCB data to a byte array.
|
/// Writes TSCB data to a byte array.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tscb"><see cref="TSCB"/> that contains data to write.</param>
|
/// <param name="tscb"><see cref="TSCB"/> that contains data to write.</param>
|
||||||
/// <returns>Byte array containing the TSCB data.</returns>
|
/// <returns>Byte array containing the TSCB data.</returns>
|
||||||
public static byte[] GetBytes(TSCB tscb)
|
public static byte[] ToBytes(TSCB tscb)
|
||||||
{
|
{
|
||||||
List<byte> b = new List<byte>();
|
List<byte> b = new List<byte>();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue