Skip to content

Commit

Permalink
Merge pull request #3 from LaneDibello/master
Browse files Browse the repository at this point in the history
Update fork master
  • Loading branch information
glasnonck authored Feb 10, 2022
2 parents 1082176 + cf3cfee commit 8daa49f
Show file tree
Hide file tree
Showing 32 changed files with 1,853 additions and 527 deletions.
14 changes: 14 additions & 0 deletions KIOTest/FieldTypeTests/ByteTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using KotOR_IO;

namespace FieldTypeTests
{
[TestClass]
public class ByteTests
{
[TestMethod]
public void TestMethod1()
{
}
}
}
59 changes: 59 additions & 0 deletions KIOTest/FileFormatTests/BIFTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.IO;
using System.Linq;
using KotOR_IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FileFormatTests
{
[TestClass]
public class BIFTests
{
/// <summary>
/// Verify that BIF.ToRawData() returns an array of data with equivalent length to the
/// data used to construct the BIF object.
/// </summary>
[TestMethod]
public void ToRawData_SimpleRead_SizeUnchanged()
{
// Arrange
var fileToRead = @"C:\Program Files (x86)\Steam\steamapps\common\swkotor\data\templates.bif";
var oldFileInfo = new FileInfo(fileToRead);
long oldSize = oldFileInfo.Length;
BIF bif = new BIF(fileToRead);

// Act
var rawData = bif.ToRawData();

// Assert
long newSize = rawData.Length;
Assert.AreEqual(oldSize, newSize, "Size of raw data has changed.");
}

/// <summary>
/// Verify that BIF.WriteToFile() creates a data file of equivalent size to the file
/// used to construct the BIF object.
/// </summary>
[TestMethod]
public void WriteToFile_ValidPath_SizeUnchanged()
{
// Arrange
var pathToRead = @"C:\Program Files (x86)\Steam\steamapps\common\swkotor\data\templates.bif";
var pathToWrite = Environment.CurrentDirectory + "templates_copy.bif";
var oldFileInfo = new FileInfo(pathToRead);
long oldSize = oldFileInfo.Length;
BIF bif = new BIF(pathToRead);

// Act
bif.WriteToFile(pathToWrite);
var newFileInfo = new FileInfo(pathToWrite);

// Assert
long newSize = newFileInfo.Length;
Assert.AreEqual(oldSize, newSize, "Size of raw data has changed.");

// Cleanup
File.Delete(pathToWrite);
}
}
}
60 changes: 60 additions & 0 deletions KIOTest/FileFormatTests/GFFTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System;
using System.IO;
using System.Linq;
using KotOR_IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace FileFormatTests
{
[TestClass]
public class GFFTests
{
/// <summary>
/// Verify that GFF.ToRawData() returns an array of data with equivalent length to the
/// data used to construct the GFF object.
/// </summary>
[TestMethod]
public void ToRawData_SimpleRead_SizeUnchanged()
{
// Arrange
var fileToRead = @"C:\Program Files (x86)\Steam\steamapps\common\swkotor\data\templates.bif";
BIF templates = new BIF(fileToRead);
var vre = templates.VariableResourceTable.First(vre => vre.ResourceType == ResourceType.UTC);
int oldSize = vre.EntryData.Length;
GFF utc = new GFF(vre.EntryData);

// Act
var rawData = utc.ToRawData();

// Assert
int newSize = rawData.Length;
Assert.AreEqual(oldSize, newSize, "Size of raw data has changed.");
}

/// <summary>
/// Verify that GFF.WriteToFile() creates a data file of equivalent size to the file
/// used to construct the GFF object.
/// </summary>
[TestMethod]
public void WriteToFile_ValidPath_SizeUnchanged()
{
// Arrange
string pathToRead = @"C:\Dev\KIO Test\test1.git";
string pathToWrite = @"C:\Dev\KIO Test\test1_copy.git";
FileInfo oldFileInfo = new FileInfo(pathToRead);
GFF gff = new GFF(pathToRead);

// Act
gff.WriteToFile(pathToWrite);
FileInfo newFileInfo = new FileInfo(pathToWrite);

// Assert
var oldFileSize = oldFileInfo.Length;
var newFileSize = newFileInfo.Length;
Assert.AreEqual(oldFileSize, newFileSize, "File size has changed.");

// Cleanup
File.Delete(pathToWrite);
}
}
}
20 changes: 20 additions & 0 deletions KIOTest/KIOTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\KotOR_IO\KotOR_IO.csproj" />
</ItemGroup>

</Project>
13 changes: 11 additions & 2 deletions KotOR_IO.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KotOR_IO", "KotOR_IO\KotOR_IO.csproj", "{DDB8235B-7C51-4810-83EC-837BF040DFC2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test8", "test8\test8.csproj", "{ABF89826-3445-433D-8CE9-F87DA18DA009}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KIOTest", "KIOTest\KIOTest.csproj", "{AC363A4C-C268-4612-B2D6-609CEBFA9C87}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,8 +23,15 @@ Global
{ABF89826-3445-433D-8CE9-F87DA18DA009}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ABF89826-3445-433D-8CE9-F87DA18DA009}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ABF89826-3445-433D-8CE9-F87DA18DA009}.Release|Any CPU.Build.0 = Release|Any CPU
{AC363A4C-C268-4612-B2D6-609CEBFA9C87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC363A4C-C268-4612-B2D6-609CEBFA9C87}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC363A4C-C268-4612-B2D6-609CEBFA9C87}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC363A4C-C268-4612-B2D6-609CEBFA9C87}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C99B0B8E-BCBF-4E28-BC04-66489EFD9B62}
EndGlobalSection
EndGlobal
74 changes: 58 additions & 16 deletions KotOR_IO/File Formats/GFF FieldTypes/0_BYTE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,37 @@ namespace KotOR_IO
{
public partial class GFF
{
/// <summary>
/// A BYTE is a 1-byte signed numeric value.
/// </summary>
public class BYTE : FIELD
{
public byte Value;
/// <summary>
/// Byte value
/// </summary>
public byte Value { get; set; }

//Construction
/// <summary>
/// Default constructor.
/// </summary>
public BYTE() : base(GffFieldType.BYTE) { }

/// <summary>
/// Construct with label and value.
/// </summary>
/// <param name="label"></param>
/// <param name="value"></param>
public BYTE(string label, byte value)
: base(GffFieldType.BYTE, label)
{
Value = value;
}

/// <summary>
/// Construct by reading a binary reader.
/// </summary>
/// <param name="br"></param>
/// <param name="offset"></param>
internal BYTE(BinaryReader br, int offset)
: base(GffFieldType.BYTE)
{
Expand All @@ -36,8 +56,20 @@ internal BYTE(BinaryReader br, int offset)
Label = new string(br.ReadChars(16)).TrimEnd('\0');
}


internal override void collect_fields(ref List<Tuple<FIELD, int, int>> Field_Array, ref List<byte> Raw_Field_Data_Block, ref List<string> Label_Array, ref int Struct_Indexer, ref int List_Indices_Counter)
/// <summary>
/// Collect fields recursively.
/// </summary>
/// <param name="Field_Array"></param>
/// <param name="Raw_Field_Data_Block"></param>
/// <param name="Label_Array"></param>
/// <param name="Struct_Indexer"></param>
/// <param name="List_Indices_Counter"></param>
internal override void collect_fields(
ref List<Tuple<FIELD, int, int>> Field_Array,
ref List<byte> Raw_Field_Data_Block,
ref List<string> Label_Array,
ref int Struct_Indexer,
ref int List_Indices_Counter)
{
Tuple<FIELD, int, int> T = new Tuple<FIELD, int, int>(this, (int)Value, this.GetHashCode());
Field_Array.Add(T);
Expand All @@ -48,23 +80,33 @@ internal override void collect_fields(ref List<Tuple<FIELD, int, int>> Field_Arr
}
}

public override bool Equals(object obj)
/// <summary>
/// Test equality between two BYTE objects.
/// </summary>
/// <param name="right"></param>
/// <returns></returns>
public override bool Equals(object right)
{
if ((obj == null) || !GetType().Equals(obj.GetType()))
{
// Check null, self, type, Gff Type, and Label
if (!base.Equals(right))
return false;
}
else
{
return Value == (obj as BYTE).Value && Label == (obj as BYTE).Label;
}
}

public override int GetHashCode()
{
return new { Type, Value, Label }.GetHashCode();
return Value == (right as BYTE).Value;
}

/// <summary>
/// Generate a hash code for this BYTE.
/// </summary>
/// <returns></returns>
//public override int GetHashCode()
//{
// return new { Type, Value, Label }.GetHashCode();
//}

/// <summary>
/// Write BYTE information to string.
/// </summary>
/// <returns>[BYTE] "Label", Value</returns>
public override string ToString()
{
return $"{base.ToString()}, {Value}";
Expand Down
Loading

0 comments on commit 8daa49f

Please sign in to comment.