Skip to content

Commit

Permalink
Merge pull request #14 from glasnonck/QoL_ToStringMethods
Browse files Browse the repository at this point in the history
Quality of live improvements to KIO
  • Loading branch information
LaneDibello authored Feb 23, 2021
2 parents 29f99fb + 0324625 commit 8787d95
Show file tree
Hide file tree
Showing 20 changed files with 391 additions and 392 deletions.
29 changes: 15 additions & 14 deletions KotOR_IO/File Formats/GFF FieldTypes/0_BYTE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,37 @@ public partial class GFF
{
public class BYTE : FIELD
{
public byte value;
public byte Value;

//Construction
public BYTE() { }
public BYTE(string Label, byte value)
public BYTE() : base(GffFieldType.BYTE) { }
public BYTE(string label, byte value)
: base(GffFieldType.BYTE, label)
{
if (Label.Length > 16) { throw new Exception($"Label \"{Label}\" is longer than 16 characters, and is invalid."); }
this.Type = 0;
this.Label = Label;
this.value = value;
Value = value;
}
internal BYTE(BinaryReader br, int offset)
: base(GffFieldType.BYTE)
{
//header info
br.BaseStream.Seek(24, 0);
int LabelOffset = br.ReadInt32();

//Basic Field Data
br.BaseStream.Seek(offset, 0);
Type = br.ReadInt32();
Type = (GffFieldType)br.ReadInt32();
int LabelIndex = br.ReadInt32();
value = br.ReadByte();
Value = br.ReadByte();

//Label Logic
br.BaseStream.Seek(LabelOffset + LabelIndex * 16, 0);
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)
{
Tuple<FIELD, int, int> T = new Tuple<FIELD, int, int>(this, (int)value, this.GetHashCode());
Tuple<FIELD, int, int> T = new Tuple<FIELD, int, int>(this, (int)Value, this.GetHashCode());
Field_Array.Add(T);

if (!Label_Array.Contains(Label))
Expand All @@ -58,16 +56,19 @@ public override bool Equals(object obj)
}
else
{
return value == (obj as BYTE).value && Label == (obj as BYTE).Label;
return Value == (obj as BYTE).Value && Label == (obj as BYTE).Label;
}
}

public override int GetHashCode()
{
return new { Type, value, Label }.GetHashCode();
return new { Type, Value, Label }.GetHashCode();
}


public override string ToString()
{
return $"{base.ToString()}, {Value}";
}
}

}
Expand Down
28 changes: 15 additions & 13 deletions KotOR_IO/File Formats/GFF FieldTypes/1_CHAR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ public partial class GFF
{
public class CHAR : FIELD
{
public char value;
public char Value;

//Construction
public CHAR() { }
public CHAR(string Label, char value)
public CHAR() : base(GffFieldType.CHAR) { }
public CHAR(string label, char value)
: base(GffFieldType.CHAR, label)
{
this.Type = 1;
if (Label.Length > 16) { throw new Exception($"Label \"{Label}\" is longer than 16 characters, and is invalid."); }
this.Label = Label;
this.value = value;
Value = value;
}
internal CHAR(BinaryReader br, int offset)
: base(GffFieldType.CHAR)
{
//header info
br.BaseStream.Seek(24, 0);
int LabelOffset = br.ReadInt32();

//Basic Field Data
br.BaseStream.Seek(offset, 0);
Type = br.ReadInt32();
Type = (GffFieldType)br.ReadInt32();
int LabelIndex = br.ReadInt32();
value = br.ReadChar();
Value = br.ReadChar();

//Label Logic
br.BaseStream.Seek(LabelOffset + LabelIndex * 16, 0);
Expand All @@ -40,7 +39,7 @@ internal CHAR(BinaryReader br, int offset)

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());
Tuple<FIELD, int, int> T = new Tuple<FIELD, int, int>(this, (int)Value, this.GetHashCode());
Field_Array.Add(T);

if (!Label_Array.Contains(Label))
Expand All @@ -57,16 +56,19 @@ public override bool Equals(object obj)
}
else
{
return value == (obj as CHAR).value && Label == (obj as CHAR).Label;
return Value == (obj as CHAR).Value && Label == (obj as CHAR).Label;
}
}

public override int GetHashCode()
{
return new { Type, value, Label }.GetHashCode();
return new { Type, Value, Label }.GetHashCode();
}


public override string ToString()
{
return $"{base.ToString()}, \'{Value}\'";
}
}
}
}
28 changes: 15 additions & 13 deletions KotOR_IO/File Formats/GFF FieldTypes/2_WORD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ public partial class GFF
{
public class WORD : FIELD
{
public ushort value;
public ushort Value;

//Construction
public WORD() { }
public WORD(string Label, ushort value)
public WORD() : base(GffFieldType.WORD) { }
public WORD(string label, ushort value)
: base(GffFieldType.WORD, label)
{
this.Type = 2;
if (Label.Length > 16) { throw new Exception($"Label \"{Label}\" is longer than 16 characters, and is invalid."); }
this.Label = Label;
this.value = value;
Value = value;
}
internal WORD(BinaryReader br, int offset)
: base(GffFieldType.WORD)
{
//header info
br.BaseStream.Seek(24, 0);
int LabelOffset = br.ReadInt32();

//Basic Field Data
br.BaseStream.Seek(offset, 0);
Type = br.ReadInt32();
Type = (GffFieldType)br.ReadInt32();
int LabelIndex = br.ReadInt32();
value = br.ReadUInt16();
Value = br.ReadUInt16();

//Label Logic
br.BaseStream.Seek(LabelOffset + LabelIndex * 16, 0);
Expand All @@ -40,7 +39,7 @@ internal WORD(BinaryReader br, int offset)

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());
Tuple<FIELD, int, int> T = new Tuple<FIELD, int, int>(this, (int)Value, this.GetHashCode());
Field_Array.Add(T);

if (!Label_Array.Contains(Label))
Expand All @@ -57,16 +56,19 @@ public override bool Equals(object obj)
}
else
{
return value == (obj as WORD).value && Label == (obj as WORD).Label;
return Value == (obj as WORD).Value && Label == (obj as WORD).Label;
}
}

public override int GetHashCode()
{
return new { Type, value, Label }.GetHashCode();
return new { Type, Value, Label }.GetHashCode();
}


public override string ToString()
{
return $"{base.ToString()}, {Value}";
}
}
}
}
28 changes: 15 additions & 13 deletions KotOR_IO/File Formats/GFF FieldTypes/3_SHORT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ public partial class GFF
{
public class SHORT : FIELD
{
public short value;
public short Value;

//Construction
public SHORT() { }
public SHORT(string Label, short value)
public SHORT() : base(GffFieldType.SHORT) { }
public SHORT(string label, short value)
: base(GffFieldType.SHORT, label)
{
this.Type = 3;
if (Label.Length > 16) { throw new Exception($"Label \"{Label}\" is longer than 16 characters, and is invalid."); }
this.Label = Label;
this.value = value;
Value = value;
}
internal SHORT(BinaryReader br, int offset)
: base(GffFieldType.SHORT)
{
//header info
br.BaseStream.Seek(24, 0);
int LabelOffset = br.ReadInt32();

//Basic Field Data
br.BaseStream.Seek(offset, 0);
Type = br.ReadInt32();
Type = (GffFieldType)br.ReadInt32();
int LabelIndex = br.ReadInt32();
value = br.ReadInt16();
Value = br.ReadInt16();

//Label Logic
br.BaseStream.Seek(LabelOffset + LabelIndex * 16, 0);
Expand All @@ -40,7 +39,7 @@ internal SHORT(BinaryReader br, int offset)

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());
Tuple<FIELD, int, int> T = new Tuple<FIELD, int, int>(this, (int)Value, this.GetHashCode());
Field_Array.Add(T);

if (!Label_Array.Contains(Label))
Expand All @@ -57,16 +56,19 @@ public override bool Equals(object obj)
}
else
{
return value == (obj as SHORT).value && Label == (obj as SHORT).Label;
return Value == (obj as SHORT).Value && Label == (obj as SHORT).Label;
}
}

public override int GetHashCode()
{
return new { Type, value, Label }.GetHashCode();
return new { Type, Value, Label }.GetHashCode();
}


public override string ToString()
{
return $"{base.ToString()}, {Value}";
}
}
}
}
28 changes: 15 additions & 13 deletions KotOR_IO/File Formats/GFF FieldTypes/4_DWORD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,27 @@ public partial class GFF
{
public class DWORD : FIELD
{
public uint value;
public uint Value;

//Construction
public DWORD() { }
public DWORD(string Label, uint value)
public DWORD() : base(GffFieldType.DWORD) { }
public DWORD(string label, uint value)
: base(GffFieldType.DWORD, label)
{
this.Type = 4;
if (Label.Length > 16) { throw new Exception($"Label \"{Label}\" is longer than 16 characters, and is invalid."); }
this.Label = Label;
this.value = value;
Value = value;
}
internal DWORD(BinaryReader br, int offset)
: base(GffFieldType.DWORD)
{
//header info
br.BaseStream.Seek(24, 0);
int LabelOffset = br.ReadInt32();

//Basic Field Data
br.BaseStream.Seek(offset, 0);
Type = br.ReadInt32();
Type = (GffFieldType)br.ReadInt32();
int LabelIndex = br.ReadInt32();
value = br.ReadUInt32();
Value = br.ReadUInt32();

//Label Logic
br.BaseStream.Seek(LabelOffset + LabelIndex * 16, 0);
Expand All @@ -40,7 +39,7 @@ internal DWORD(BinaryReader br, int offset)

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, BitConverter.ToInt32((BitConverter.GetBytes(value)), 0), this.GetHashCode());
Tuple<FIELD, int, int> T = new Tuple<FIELD, int, int>(this, BitConverter.ToInt32((BitConverter.GetBytes(Value)), 0), this.GetHashCode());
Field_Array.Add(T);

if (!Label_Array.Contains(Label))
Expand All @@ -57,16 +56,19 @@ public override bool Equals(object obj)
}
else
{
return value == (obj as DWORD).value && Label == (obj as DWORD).Label;
return Value == (obj as DWORD).Value && Label == (obj as DWORD).Label;
}
}

public override int GetHashCode()
{
return new { Type, value, Label }.GetHashCode();
return new { Type, Value, Label }.GetHashCode();
}


public override string ToString()
{
return $"{base.ToString()}, {Value}";
}
}
}
}
Loading

0 comments on commit 8787d95

Please sign in to comment.