Skip to content

Commit e773a23

Browse files
committed
Various small changes.
1 parent 3b18924 commit e773a23

19 files changed

+52
-73
lines changed

CodeGenerator/CSharpCodeGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ private IEnumerable<MemberDefinition> YieldMemberDefinitions(IEnumerable<BaseNod
8787

8888
foreach (var member in members.WhereNot(n => n is BaseHexNode))
8989
{
90-
if (member is BitFieldNode)
90+
var bitFieldNode = member as BitFieldNode;
91+
if (bitFieldNode != null)
9192
{
9293
string type;
93-
switch (((BitFieldNode)member).Bits)
94+
switch (bitFieldNode.Bits)
9495
{
9596
default:
96-
case 8:
9797
type = typeToTypedefMap[typeof(UInt8Node)];
9898
break;
9999
case 16:

CodeGenerator/CppCodeGenerator.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ class CppCodeGenerator : ICodeGenerator
4343

4444
public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
4545
{
46+
var classNodes = classes as IList<ClassNode> ?? classes.ToList();
47+
4648
var sb = new StringBuilder();
4749
sb.AppendLine($"// Created with {Constants.ApplicationName} by {Constants.Author}");
4850
sb.AppendLine();
4951
sb.AppendLine(
5052
string.Join(
5153
"\n\n",
52-
OrderByInheritance(classes.Where(c => c.Nodes.None(n => n is FunctionNode))).Select(c =>
54+
OrderByInheritance(classNodes.Where(c => c.Nodes.None(n => n is FunctionNode))).Select(c =>
5355
{
5456
var csb = new StringBuilder();
5557
csb.Append($"class {c.Name}");
@@ -81,26 +83,26 @@ public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
8183
)
8284
);
8385

84-
var vtables = c.Nodes.OfType<VTableNode>();
85-
if (vtables.Any())
86+
var vTableNodes = c.Nodes.OfType<VTableNode>().ToList();
87+
if (vTableNodes.Any())
8688
{
8789
csb.AppendLine();
8890
csb.AppendLine(
8991
string.Join(
9092
"\n",
91-
vtables.SelectMany(vt => vt.Nodes).OfType<VMethodNode>().Select(m => $"\tvirtual void {m.MethodName}();")
93+
vTableNodes.SelectMany(vt => vt.Nodes).OfType<VMethodNode>().Select(m => $"\tvirtual void {m.MethodName}();")
9294
)
9395
);
9496
}
9597

96-
var functions = classes.SelectMany(c2 => c2.Nodes).OfType<FunctionNode>().Where(f => f.BelongsToClass == c);
97-
if (functions.Any())
98+
var functionNodes = classNodes.SelectMany(c2 => c2.Nodes).OfType<FunctionNode>().Where(f => f.BelongsToClass == c).ToList();
99+
if (functionNodes.Any())
98100
{
99101
csb.AppendLine();
100102
csb.AppendLine(
101103
string.Join(
102104
"\n",
103-
functions.Select(f => $"\t{f.Signature} {{ }}")
105+
functionNodes.Select(f => $"\t{f.Signature} {{ }}")
104106
)
105107
);
106108
}
@@ -139,7 +141,7 @@ private IEnumerable<ClassNode> YieldReversedHierarchy(ClassNode node, HashSet<Cl
139141

140142
foreach (var referenceNode in node.Nodes.OfType<BaseReferenceNode>())
141143
{
142-
foreach (var referencedNode in YieldReversedHierarchy(referenceNode.InnerNode as ClassNode, alreadySeen))
144+
foreach (var referencedNode in YieldReversedHierarchy(referenceNode.InnerNode, alreadySeen))
143145
{
144146
yield return referencedNode;
145147
}
@@ -181,11 +183,7 @@ private IEnumerable<MemberDefinition> YieldMemberDefinitions(IEnumerable<BaseNod
181183
string type;
182184
if (typeToTypedefMap.TryGetValue(member.GetType(), out type))
183185
{
184-
int count = 0;
185-
if (member is BaseTextNode)
186-
{
187-
count = ((BaseTextNode)member).Length;
188-
}
186+
var count = (member as BaseTextNode)?.Length ?? 0;
189187

190188
yield return new MemberDefinition(member, type, count);
191189
}
@@ -257,10 +255,7 @@ private string MemberDefinitionToString(MemberDefinition member)
257255
{
258256
return $"{member.Type} {member.Name}[{member.ArrayCount}]; //0x{member.Offset:X04} {member.Comment}".Trim();
259257
}
260-
else
261-
{
262-
return $"{member.Type} {member.Name}; //0x{member.Offset:X04} {member.Comment}".Trim();
263-
}
258+
return $"{member.Type} {member.Name}; //0x{member.Offset:X04} {member.Comment}".Trim();
264259
}
265260
}
266261
}

DataExchange/ReClassFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace ReClassNET.DataExchange
1212
{
13-
partial class ReClassFile : IReClassImport
13+
class ReClassFile : IReClassImport
1414
{
1515
public const string FormatName = "ReClass File";
1616
public const string FileExtension = ".reclass";

Debugger/RemoteDebugger.Thread.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public partial class RemoteDebugger
1111
private Thread thread;
1212

1313
private volatile bool running = true;
14-
private volatile bool isAttached = false;
14+
private volatile bool isAttached;
1515

1616
public bool IsAttached => isAttached;
1717

Debugger/RemoteDebugger.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ private List<BreakpointSplit> SplitBreakpoint(IntPtr address, int size)
174174

175175
address += 1;
176176
size -= 1;
177-
178-
continue;
179177
}
180178
}
181179

Debugger/SoftwareBreakpoint.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public bool Set(RemoteProcess process)
3636

3737
public void Remove(RemoteProcess process)
3838
{
39-
process.WriteRemoteMemory(Address, new byte[] { orig });
39+
process.WriteRemoteMemory(Address, new[] { orig });
4040
}
4141

4242
public void Handler(ref DebugEvent evt)

Forms/MainForm.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public partial class MainForm : IconForm
2424
private readonly CoreFunctionsManager coreFunctions;
2525

2626
private readonly RemoteProcess remoteProcess;
27-
private readonly MemoryBuffer memory;
2827

2928
private readonly PluginManager pluginManager;
3029

@@ -41,7 +40,6 @@ public MainForm(CoreFunctionsManager coreFunctions)
4140
{
4241
Contract.Requires(coreFunctions != null);
4342
Contract.Ensures(remoteProcess != null);
44-
Contract.Ensures(memory != null);
4543
Contract.Ensures(pluginManager != null);
4644
Contract.Ensures(currentProject != null);
4745

@@ -66,13 +64,11 @@ public MainForm(CoreFunctionsManager coreFunctions)
6664
processInfoToolStripStatusLabel.Text = "No process selected";
6765
};
6866

69-
memory = new MemoryBuffer
67+
memoryViewControl.Memory = new MemoryBuffer
7068
{
7169
Process = remoteProcess
7270
};
7371

74-
memoryViewControl.Memory = memory;
75-
7672
pluginManager = new PluginManager(new DefaultPluginHost(this, remoteProcess, Program.Logger), coreFunctions);
7773

7874
SetProject(new ReClassNetProject());
@@ -95,7 +91,7 @@ protected override void OnFormClosed(FormClosedEventArgs e)
9591

9692
GlobalWindowManager.RemoveWindow(this);
9793

98-
base.OnClosed(e);
94+
base.OnFormClosed(e);
9995
}
10096

10197
#region Event Handler

Forms/PluginForm.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Data;
32
using System.Diagnostics;
43
using System.Diagnostics.Contracts;
54
using System.Drawing;

Native/NativeMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static NativeMethods()
2020
}
2121
}
2222

23-
private static bool? isUnix = null;
23+
private static bool? isUnix;
2424
public static bool IsUnix()
2525
{
2626
if (isUnix.HasValue)
@@ -35,7 +35,7 @@ public static bool IsUnix()
3535
return isUnix.Value;
3636
}
3737

38-
private static PlatformID? plattformId = null;
38+
private static PlatformID? plattformId;
3939
public static PlatformID GetPlatformID()
4040
{
4141
if (plattformId.HasValue)

NativeCore/Windows/DisassembleCode.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#include <windows.h>
2-
#include <vector>
3-
#include <cstdint>
42
#include <beaengine/BeaEngine.h>
53

64
#include "NativeCore.hpp"

Nodes/BaseHexNode.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ public override int CalculateHeight(ViewInfo view)
7474

7575
/// <summary>Updates the node from the given spot. Sets the value of the selected byte.</summary>
7676
/// <param name="spot">The spot.</param>
77-
public void Update(HotSpot spot, int length)
77+
/// <param name="maxId">The highest spot id.</param>
78+
public void Update(HotSpot spot, int maxId)
7879
{
7980
Contract.Requires(spot != null);
8081

8182
base.Update(spot);
8283

83-
if (spot.Id >= 0 && spot.Id < length)
84+
if (spot.Id >= 0 && spot.Id < maxId)
8485
{
8586
byte val;
8687
if (byte.TryParse(spot.Text, NumberStyles.HexNumber, null, out val))

Nodes/ClassUtil.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,11 @@ public static bool IsCycleFree(ClassNode parent, ClassNode check, IEnumerable<Cl
3434
.Traverse(
3535
c => c.Nodes
3636
.Where(n => n is ClassInstanceNode || n is ClassInstanceArrayNode)
37-
.Select(n => ((BaseReferenceNode)n).InnerNode as ClassNode)
37+
.Select(n => ((BaseReferenceNode)n).InnerNode)
3838
)
3939
);
4040

41-
if (!IsCycleFree(parent, toCheck, classes))
42-
{
43-
return false;
44-
}
45-
46-
return true;
41+
return IsCycleFree(parent, toCheck, classes);
4742
}
4843

4944
private static bool IsCycleFree(ClassNode root, HashSet<ClassNode> seen, IEnumerable<ClassNode> classes)
@@ -58,15 +53,15 @@ private static bool IsCycleFree(ClassNode root, HashSet<ClassNode> seen, IEnumer
5853
return false;
5954
}
6055

61-
foreach (var cls in classes/*.Except(seen)*/)
56+
var classNodes = classes as IList<ClassNode> ?? classes.ToList();
57+
foreach (var cls in classNodes/*.Except(seen)*/)
6258
{
6359
if (cls.Nodes
6460
.OfType<BaseReferenceNode>()
6561
.Where(n => n is ClassInstanceNode || n is ClassInstanceArrayNode)
66-
.Where(n => n.InnerNode == root)
67-
.Any())
62+
.Any(n => n.InnerNode == root))
6863
{
69-
if (!IsCycleFree(cls, seen, classes))
64+
if (!IsCycleFree(cls, seen, classNodes))
7065
{
7166
return false;
7267
}

Plugins/PluginManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal sealed class PluginManager : IEnumerable<PluginInfo>
1515
{
1616
private readonly List<PluginInfo> plugins = new List<PluginInfo>();
1717

18-
private readonly IPluginHost host = null;
18+
private readonly IPluginHost host;
1919
private readonly CoreFunctionsManager coreFunctions;
2020

2121
public PluginManager(IPluginHost host, CoreFunctionsManager coreFunctions)

Symbols/SymbolStore.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ namespace ReClassNET.Symbols
1414
{
1515
class DiaUtil : IDisposable
1616
{
17-
public readonly IDiaDataSource _IDiaDataSource;
18-
public readonly IDiaSession _IDiaSession;
17+
public readonly IDiaDataSource diaDataSource;
18+
public readonly IDiaSession diaSession;
1919

2020
public DiaUtil(string pdbName)
2121
{
2222
Contract.Requires(pdbName != null);
2323

24-
_IDiaDataSource = new DiaSource();
25-
_IDiaDataSource.loadDataFromPdb(pdbName);
26-
_IDiaDataSource.openSession(out _IDiaSession);
24+
diaDataSource = new DiaSource();
25+
diaDataSource.loadDataFromPdb(pdbName);
26+
diaDataSource.openSession(out diaSession);
2727
}
2828

29-
private bool disposedValue = false;
29+
private bool isDisposed;
3030

3131
protected virtual void Dispose(bool disposing)
3232
{
33-
if (!disposedValue)
33+
if (!isDisposed)
3434
{
35-
Marshal.ReleaseComObject(_IDiaSession);
36-
Marshal.ReleaseComObject(_IDiaDataSource);
35+
Marshal.ReleaseComObject(diaSession);
36+
Marshal.ReleaseComObject(diaDataSource);
3737

38-
disposedValue = true;
38+
isDisposed = true;
3939
}
4040
}
4141

UI/ClassNodeView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private class ClassTreeNode : TreeNode, IDisposable
3434

3535
/// <summary>Constructor of the class.</summary>
3636
/// <param name="node">The class node.</param>
37+
/// <param name="enableHierarchyView">The value if the hierarchy view is enabled.</param>
3738
/// <param name="autoExpand">The value if nodes should get expanded.</param>
3839
public ClassTreeNode(ClassNode node, ValueWrapper<bool> enableHierarchyView, ValueWrapper<bool> autoExpand)
3940
: this(node, enableHierarchyView, autoExpand, null)
@@ -98,7 +99,6 @@ private void RebuildClassHierarchy(HashSet<ClassNode> seen)
9899
var distinctClasses = ClassNode.Nodes
99100
.OfType<BaseReferenceNode>()
100101
.Select(r => r.InnerNode)
101-
.OfType<ClassNode>()
102102
.Distinct()
103103
.ToList();
104104

UI/DpiUtil.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class DpiUtil
1111
{
1212
private const int StdDpi = 96;
1313

14-
private static bool initialized = false;
14+
private static bool initialized;
1515

1616
private static int dpiX = StdDpi;
1717
private static int dpiY = StdDpi;
@@ -60,8 +60,8 @@ private static void EnsureInitialized()
6060

6161
}
6262

63-
scaleX = (double)dpiX / (double)StdDpi;
64-
scaleY = (double)dpiY / (double)StdDpi;
63+
scaleX = dpiX / (double)StdDpi;
64+
scaleY = dpiY / (double)StdDpi;
6565

6666
initialized = true;
6767
}

UI/MemoryPreviewToolTip.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public MemoryBuffer Memory
3737

3838
private readonly ViewInfo viewInfo;
3939

40-
private Size size = new Size();
40+
private Size size;
4141

4242
public MemoryPreviewToolTip()
4343
{

UI/MemoryViewControl.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ partial class MemoryViewControl : ScrollableCustomControl
2222
private readonly List<HotSpot> hotSpots = new List<HotSpot>();
2323
private readonly List<HotSpot> selectedNodes = new List<HotSpot>();
2424

25-
private HotSpot selectionCaret = null;
26-
private HotSpot selectionAnchor = null;
25+
private HotSpot selectionCaret;
26+
private HotSpot selectionAnchor;
2727

2828
private readonly FontEx font;
2929

@@ -36,10 +36,7 @@ public ReClassNetProject Project
3636
{
3737
Contract.Requires(value != null);
3838

39-
if (project != value)
40-
{
41-
project = value;
42-
}
39+
project = value;
4340
}
4441
}
4542

@@ -792,7 +789,7 @@ private void createClassFromNodesToolStripMenuItem_Click(object sender, EventArg
792789

793790
private void dissectNodesToolStripMenuItem_Click(object sender, EventArgs e)
794791
{
795-
var hexNodes = selectedNodes.Where(h => h.Node is BaseHexNode);
792+
var hexNodes = selectedNodes.Where(h => h.Node is BaseHexNode).ToList();
796793
if (hexNodes.Any())
797794
{
798795
foreach (var g in hexNodes.GroupBy(n => n.Node.ParentNode))

Util/Rtf/RtfBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public override string ToString()
274274
sb.AppendFormat(@"\fs{0} ", DefaultFontSize);
275275
sb.AppendLine();
276276

277-
sb.Append(buffer.ToString());
277+
sb.Append(buffer);
278278
sb.Append("}");
279279

280280
return sb.ToString();

0 commit comments

Comments
 (0)