Skip to content

Commit

Permalink
Do some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iMrShadow committed Oct 8, 2024
1 parent 396a72e commit 6c0e9d5
Show file tree
Hide file tree
Showing 32 changed files with 951 additions and 1,166 deletions.
1 change: 0 additions & 1 deletion TelltaleTextureTool/TelltaleTextureTool/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<!-- <Style Selector="ads:MsBox"> -->
<!-- <Setter Property="Background" Value="#FFDDDDDD" /> -->
<!-- </Style> -->
<avalonia:HyperLinkStyle />

<Style Selector="mscontrols|MsBoxStandardView">
<Setter Property="Background"
Expand Down
2 changes: 1 addition & 1 deletion TelltaleTextureTool/TelltaleTextureTool/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public override void OnFrameworkInitializationCompleted()
{
try
{
Logger.Instance().Log(e);
Logger.Log(e);
}
catch (IOException ex)
{
Expand Down
118 changes: 6 additions & 112 deletions TelltaleTextureTool/TelltaleTextureTool/Common/ByteFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace TelltaleTextureTool.Utilities;
public static class ByteFunctions
{
/// <summary>
///
/// Get the number of all items in a list of byte arrays
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
Expand Down Expand Up @@ -43,25 +43,6 @@ public static string ReadString(BinaryReader reader)
return value;
}

public static string ReadNullTerminatedString(BinaryReader reader)
{
StringBuilder sb = new();

// If files names longer than 256 characters exist, then I woudld be impressed.
for (int i = 0; i < 256; i++)
{
char c = reader.ReadChar();
if (c != '\0')
{
break;
}

sb.Append(c);
}

return sb.ToString();
}

public static string ReadFixedString(BinaryReader reader, int length)
{
string value = "";
Expand All @@ -78,15 +59,12 @@ public static bool ReadTelltaleBoolean(BinaryReader reader)
{
char parsedChar = reader.ReadChar();

switch (parsedChar)
return parsedChar switch
{
case '1':
return true;
case '0':
return false;
default:
throw new Exception("Invalid Telltale Boolean data.");
}
'1' => true,
'0' => false,
_ => throw new Exception("Invalid Telltale Boolean data."),
};
}

/// <summary>
Expand Down Expand Up @@ -124,23 +102,6 @@ public static void WriteFixedString(BinaryWriter writer, string value)
/// <param name="value"></param>
public static void WriteBoolean(BinaryWriter writer, bool value) => writer.Write(value ? '1' : '0');

public static byte[] GetBytes(string stringValue)
{
//create byte array of the length of the string
byte[] stringBytes = new byte[stringValue.Length];

//for the length of the string, get each byte value
for (int i = 0; i < stringBytes.Length; i++)
{
stringBytes[i] = Convert.ToByte(stringValue[i]);
}

//return it
return stringBytes;
}

public static uint ConvertStringToUInt32(string sValue) => BitConverter.ToUInt32(GetBytes(sValue), 0);

/// <summary>
/// Combines two byte arrays into one.
/// </summary>
Expand All @@ -162,75 +123,8 @@ public static byte[] Combine(byte[] first, byte[] second)
return bytes;
}

/// <summary>
/// Checks if the pointer position is at the DCArray capacity, if's not then it moves the pointer past where it should be after reading the DCArray.
/// </summary>
/// <param name="pointerPositionBeforeCapacity"></param>
/// <param name="arrayCapacity"></param>
/// <param name="bytePointerPosition"></param>
public static void DCArrayCheckAdjustment(uint pointerPositionBeforeCapacity, uint arrayCapacity, ref uint bytePointerPosition)
{
uint estimatedOffPoint = pointerPositionBeforeCapacity + arrayCapacity;
Console.WriteLine("(DCArray Check) Estimated to be at = {0}", estimatedOffPoint);

if (bytePointerPosition != estimatedOffPoint)
{
Console.WriteLine("(DCArray Check) Left off at = {0}", bytePointerPosition);
Console.WriteLine("(DCArray Check) Skipping by using the estimated position...", bytePointerPosition);
bytePointerPosition = estimatedOffPoint;
}
else
{
Console.WriteLine("(DCArray Check) Left off at = {0}", bytePointerPosition);
}

}

/// <summary>
/// Checks if we have reached the end of the file.
/// </summary>
/// <param name="bytePointerPosition"></param>
/// <param name="fileSize"></param>
public static void ReachedEndOfFile(uint bytePointerPosition, uint fileSize)
{
if (bytePointerPosition != fileSize)
{
Console.WriteLine("(End Of File Check) Didn't reach the end of the file!");
Console.WriteLine("(End Of File Check) Left off at = {0}", bytePointerPosition);
Console.WriteLine("(End Of File Check) File Size = {0}", fileSize);
}
else
{
Console.WriteLine("(End Of File Check) Reached end of file!");
Console.WriteLine("(End Of File Check) Left off at = {0}", bytePointerPosition);
Console.WriteLine("(End Of File Check) File Size = {0}", fileSize);
}
}

public static byte[] LoadTexture(string path) => File.ReadAllBytes(path);

/// <summary>
/// Checks if we have reached a specific offset in the file.
/// </summary>
/// <param name="bytePointerPosition"></param>
/// <param name="offsetPoint"></param>
public static void ReachedOffset(uint bytePointerPosition, uint offsetPoint)
{
if (bytePointerPosition != offsetPoint)
{
Console.WriteLine("(Offset Check) Didn't reach the offset!");
Console.WriteLine("(Offset Check) Left off at = {0}", bytePointerPosition);
Console.WriteLine("(Offset Check) Offset = {0}", offsetPoint);
}
else
{
Console.WriteLine("(Offset Check) Reached the offset!");
Console.WriteLine("(Offset Check) Left off at = {0}", bytePointerPosition);
Console.WriteLine("(Offset Check) Offset = {0}", offsetPoint);
}

}

public static byte[] GetBytesAfterBytePattern(string searchString, byte[] fileBytes)
{
byte[] searchBytes = Encoding.ASCII.GetBytes(searchString);
Expand Down
Loading

0 comments on commit 6c0e9d5

Please sign in to comment.