Skip to content

Commit 99f5a9f

Browse files
committed
Removed redundant code.
1 parent 8468a62 commit 99f5a9f

File tree

5 files changed

+24
-63
lines changed

5 files changed

+24
-63
lines changed

ReClass.NET/Memory/MemoryBuffer.cs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,17 @@ public string ReadPrintableAsciiString(int offset, int length)
502502
return sb.ToString();
503503
}
504504

505-
private string ReadString(Encoding encoding, int offset, int length)
505+
public string ReadString(Encoding encoding, IntPtr offset, int length)
506+
{
507+
Contract.Requires(encoding != null);
508+
Contract.Requires(offset.ToInt32() >= 0);
509+
Contract.Requires(length >= 0);
510+
Contract.Ensures(Contract.Result<string>() != null);
511+
512+
return ReadString(encoding, offset.ToInt32(), length);
513+
}
514+
515+
public string ReadString(Encoding encoding, int offset, int length)
506516
{
507517
Contract.Requires(encoding != null);
508518
Contract.Requires(offset >= 0);
@@ -525,33 +535,6 @@ private string ReadString(Encoding encoding, int offset, int length)
525535
return sb.ToString();
526536
}
527537

528-
public string ReadUtf8String(IntPtr offset, int length)
529-
{
530-
Contract.Requires(offset.ToInt32() >= 0);
531-
Contract.Requires(length >= 0);
532-
Contract.Ensures(Contract.Result<string>() != null);
533-
534-
return ReadString(Encoding.UTF8, offset.ToInt32(), length);
535-
}
536-
537-
public string ReadUtf16String(IntPtr offset, int length)
538-
{
539-
Contract.Requires(offset.ToInt32() >= 0);
540-
Contract.Requires(length >= 0);
541-
Contract.Ensures(Contract.Result<string>() != null);
542-
543-
return ReadString(Encoding.Unicode, offset.ToInt32(), length);
544-
}
545-
546-
public string ReadUtf32String(IntPtr offset, int length)
547-
{
548-
Contract.Requires(offset.ToInt32() >= 0);
549-
Contract.Requires(length >= 0);
550-
Contract.Ensures(Contract.Result<string>() != null);
551-
552-
return ReadString(Encoding.UTF32, offset.ToInt32(), length);
553-
}
554-
555538
public bool HasChanged(IntPtr offset, int length)
556539
{
557540
return HasChanged(offset.ToInt32(), length);

ReClass.NET/Nodes/BaseTextNode.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Diagnostics.Contracts;
33
using System.Drawing;
44
using System.Text;
5+
using ReClassNET.Memory;
56
using ReClassNET.UI;
67
using ReClassNET.Util;
78

@@ -25,17 +26,19 @@ public override void CopyFromNode(BaseNode node)
2526
Length = node.MemorySize / CharacterSize;
2627
}
2728

28-
protected Size DrawText(ViewInfo view, int x, int y, string type, int length, string text)
29+
protected Size DrawText(ViewInfo view, int x, int y, string type)
2930
{
3031
Contract.Requires(view != null);
3132
Contract.Requires(type != null);
32-
Contract.Requires(text != null);
3333

3434
if (IsHidden)
3535
{
3636
return DrawHidden(view, x, y);
3737
}
3838

39+
var length = MemorySize / CharacterSize;
40+
var text = ReadValueFromMemory(view.Memory);
41+
3942
DrawInvalidMemoryIndicator(view, y);
4043

4144
var origX = x;
@@ -83,6 +86,11 @@ public override void Update(HotSpot spot)
8386
}
8487
}
8588
}
89+
90+
public string ReadValueFromMemory(MemoryBuffer memory)
91+
{
92+
return memory.ReadString(Encoding, Offset, MemorySize);
93+
}
8694
}
8795

8896
[ContractClassFor(typeof(BaseTextNode))]

ReClass.NET/Nodes/UTF16TextNode.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,9 @@ public class Utf16TextNode : BaseTextNode
1111

1212
public override Encoding Encoding => Encoding.Unicode;
1313

14-
/// <summary>Draws this node.</summary>
15-
/// <param name="view">The view information.</param>
16-
/// <param name="x">The x coordinate.</param>
17-
/// <param name="y">The y coordinate.</param>
18-
/// <returns>The pixel size the node occupies.</returns>
1914
public override Size Draw(ViewInfo view, int x, int y)
2015
{
21-
return DrawText(view, x, y, "Text16", MemorySize / CharacterSize, view.Memory.ReadUtf16String(Offset, MemorySize));
22-
}
23-
24-
public string ReadValueFromMemory(MemoryBuffer memory)
25-
{
26-
return memory.ReadUtf16String(Offset, MemorySize);
16+
return DrawText(view, x, y, "Text16");
2717
}
2818
}
2919
}

ReClass.NET/Nodes/UTF32TextNode.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,9 @@ public class Utf32TextNode : BaseTextNode
1111

1212
public override Encoding Encoding => Encoding.UTF32;
1313

14-
/// <summary>Draws this node.</summary>
15-
/// <param name="view">The view information.</param>
16-
/// <param name="x">The x coordinate.</param>
17-
/// <param name="y">The y coordinate.</param>
18-
/// <returns>The pixel size the node occupies.</returns>
1914
public override Size Draw(ViewInfo view, int x, int y)
2015
{
21-
return DrawText(view, x, y, "Text32", MemorySize / CharacterSize, view.Memory.ReadUtf32String(Offset, MemorySize));
22-
}
23-
24-
public string ReadValueFromMemory(MemoryBuffer memory)
25-
{
26-
return memory.ReadUtf32String(Offset, MemorySize);
16+
return DrawText(view, x, y, "Text32");
2717
}
2818
}
2919
}

ReClass.NET/Nodes/UTF8TextNode.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,9 @@ public class Utf8TextNode : BaseTextNode
1111

1212
public override Encoding Encoding => Encoding.UTF8;
1313

14-
/// <summary>Draws this node.</summary>
15-
/// <param name="view">The view information.</param>
16-
/// <param name="x">The x coordinate.</param>
17-
/// <param name="y">The y coordinate.</param>
18-
/// <returns>The pixel size the node occupies.</returns>
1914
public override Size Draw(ViewInfo view, int x, int y)
2015
{
21-
return DrawText(view, x, y, "Text8", MemorySize, view.Memory.ReadUtf8String(Offset, MemorySize));
22-
}
23-
24-
public string ReadValueFromMemory(MemoryBuffer memory)
25-
{
26-
return memory.ReadUtf8String(Offset, MemorySize);
16+
return DrawText(view, x, y, "Text8");
2717
}
2818
}
2919
}

0 commit comments

Comments
 (0)