Skip to content

Commit e277af1

Browse files
committed
Moved project in subfolder (1).
1 parent ccd0e93 commit e277af1

File tree

396 files changed

+7171
-7171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

396 files changed

+7171
-7171
lines changed

ReClass.NET.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReClass.NET", "ReClass.NET.csproj", "{BFB8917D-E9B4-463F-A6E8-612C35728C78}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReClass.NET", "ReClass.NET\ReClass.NET.csproj", "{BFB8917D-E9B4-463F-A6E8-612C35728C78}"
77
ProjectSection(ProjectDependencies) = postProject
88
{22CA6FDB-7622-4F94-8FC2-2E7AB481C86F} = {22CA6FDB-7622-4F94-8FC2-2E7AB481C86F}
99
EndProjectSection
File renamed without changes.
File renamed without changes.
Lines changed: 148 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,148 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics.Contracts;
4-
using System.Linq;
5-
using System.Text;
6-
using ReClassNET.Logger;
7-
using ReClassNET.Nodes;
8-
using ReClassNET.Util;
9-
10-
namespace ReClassNET.CodeGenerator
11-
{
12-
class CSharpCodeGenerator : ICodeGenerator
13-
{
14-
private readonly Dictionary<Type, string> typeToTypedefMap = new Dictionary<Type, string>
15-
{
16-
[typeof(DoubleNode)] = "double",
17-
[typeof(FloatNode)] = "float",
18-
[typeof(BoolNode)] = "bool",
19-
[typeof(Int8Node)] = "sbyte",
20-
[typeof(Int16Node)] = "short",
21-
[typeof(Int32Node)] = "int",
22-
[typeof(Int64Node)] = "long",
23-
[typeof(UInt8Node)] = "byte",
24-
[typeof(UInt16Node)] = "ushort",
25-
[typeof(UInt32Node)] = "uint",
26-
[typeof(UInt64Node)] = "ulong",
27-
28-
[typeof(FunctionPtrNode)] = "IntPtr",
29-
[typeof(Utf8TextPtrNode)] = "IntPtr",
30-
[typeof(Utf16TextPtrNode)] = "IntPtr",
31-
[typeof(Utf32TextPtrNode)] = "IntPtr",
32-
[typeof(ClassPtrNode)] = "IntPtr",
33-
[typeof(VTableNode)] = "IntPtr"
34-
};
35-
36-
public Language Language => Language.CSharp;
37-
38-
public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
39-
{
40-
var sb = new StringBuilder();
41-
sb.AppendLine($"// Created with {Constants.ApplicationName} by {Constants.Author}");
42-
sb.AppendLine();
43-
sb.AppendLine("// Warning: The code doesn't contain arrays and instances!");
44-
sb.AppendLine();
45-
sb.AppendLine("using System.Runtime.InteropServices;");
46-
sb.AppendLine();
47-
48-
sb.Append(
49-
string.Join(
50-
Environment.NewLine + Environment.NewLine,
51-
classes.Select(c =>
52-
{
53-
var csb = new StringBuilder();
54-
55-
csb.AppendLine("[StructLayout(LayoutKind.Explicit)]");
56-
csb.Append($"struct {c.Name}");
57-
if (!string.IsNullOrEmpty(c.Comment))
58-
{
59-
csb.Append($" // {c.Comment}");
60-
}
61-
csb.AppendLine();
62-
63-
csb.AppendLine("{");
64-
65-
csb.AppendLine(
66-
string.Join(
67-
Environment.NewLine + Environment.NewLine,
68-
YieldMemberDefinitions(c.Nodes, logger)
69-
.Select(m => $"\t{GetFieldDecorator(m)}{Environment.NewLine}\t{GetFieldDefinition(m)}")
70-
)
71-
);
72-
csb.Append("}");
73-
return csb.ToString();
74-
})
75-
)
76-
);
77-
78-
return sb.ToString();
79-
}
80-
81-
private IEnumerable<MemberDefinition> YieldMemberDefinitions(IEnumerable<BaseNode> members, ILogger logger)
82-
{
83-
Contract.Requires(members != null);
84-
Contract.Requires(Contract.ForAll(members, m => m != null));
85-
Contract.Ensures(Contract.Result<IEnumerable<MemberDefinition>>() != null);
86-
Contract.Ensures(Contract.ForAll(Contract.Result<IEnumerable<MemberDefinition>>(), d => d != null));
87-
88-
foreach (var member in members.WhereNot(n => n is BaseHexNode))
89-
{
90-
var bitFieldNode = member as BitFieldNode;
91-
if (bitFieldNode != null)
92-
{
93-
string type;
94-
switch (bitFieldNode.Bits)
95-
{
96-
default:
97-
type = typeToTypedefMap[typeof(UInt8Node)];
98-
break;
99-
case 16:
100-
type = typeToTypedefMap[typeof(UInt16Node)];
101-
break;
102-
case 32:
103-
type = typeToTypedefMap[typeof(UInt32Node)];
104-
break;
105-
case 64:
106-
type = typeToTypedefMap[typeof(UInt64Node)];
107-
break;
108-
}
109-
110-
yield return new MemberDefinition(member, type);
111-
}
112-
else
113-
{
114-
if (typeToTypedefMap.TryGetValue(member.GetType(), out var type))
115-
{
116-
yield return new MemberDefinition(member, type);
117-
}
118-
else
119-
{
120-
var generator = CustomCodeGenerator.GetGenerator(member, Language);
121-
if (generator != null)
122-
{
123-
yield return generator.GetMemberDefinition(member, Language, logger);
124-
125-
continue;
126-
}
127-
128-
logger.Log(LogLevel.Error, $"Skipping node with unhandled type: {member.GetType()}");
129-
}
130-
}
131-
}
132-
}
133-
134-
private string GetFieldDecorator(MemberDefinition member)
135-
{
136-
Contract.Requires(member != null);
137-
138-
return $"[FieldOffset({member.Offset})]";
139-
}
140-
141-
private string GetFieldDefinition(MemberDefinition member)
142-
{
143-
Contract.Requires(member != null);
144-
145-
return $"public {member.Type} {member.Name}; //0x{member.Offset:X04} {member.Comment}".Trim();
146-
}
147-
}
148-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.Contracts;
4+
using System.Linq;
5+
using System.Text;
6+
using ReClassNET.Logger;
7+
using ReClassNET.Nodes;
8+
using ReClassNET.Util;
9+
10+
namespace ReClassNET.CodeGenerator
11+
{
12+
class CSharpCodeGenerator : ICodeGenerator
13+
{
14+
private readonly Dictionary<Type, string> typeToTypedefMap = new Dictionary<Type, string>
15+
{
16+
[typeof(DoubleNode)] = "double",
17+
[typeof(FloatNode)] = "float",
18+
[typeof(BoolNode)] = "bool",
19+
[typeof(Int8Node)] = "sbyte",
20+
[typeof(Int16Node)] = "short",
21+
[typeof(Int32Node)] = "int",
22+
[typeof(Int64Node)] = "long",
23+
[typeof(UInt8Node)] = "byte",
24+
[typeof(UInt16Node)] = "ushort",
25+
[typeof(UInt32Node)] = "uint",
26+
[typeof(UInt64Node)] = "ulong",
27+
28+
[typeof(FunctionPtrNode)] = "IntPtr",
29+
[typeof(Utf8TextPtrNode)] = "IntPtr",
30+
[typeof(Utf16TextPtrNode)] = "IntPtr",
31+
[typeof(Utf32TextPtrNode)] = "IntPtr",
32+
[typeof(ClassPtrNode)] = "IntPtr",
33+
[typeof(VTableNode)] = "IntPtr"
34+
};
35+
36+
public Language Language => Language.CSharp;
37+
38+
public string GenerateCode(IEnumerable<ClassNode> classes, ILogger logger)
39+
{
40+
var sb = new StringBuilder();
41+
sb.AppendLine($"// Created with {Constants.ApplicationName} by {Constants.Author}");
42+
sb.AppendLine();
43+
sb.AppendLine("// Warning: The code doesn't contain arrays and instances!");
44+
sb.AppendLine();
45+
sb.AppendLine("using System.Runtime.InteropServices;");
46+
sb.AppendLine();
47+
48+
sb.Append(
49+
string.Join(
50+
Environment.NewLine + Environment.NewLine,
51+
classes.Select(c =>
52+
{
53+
var csb = new StringBuilder();
54+
55+
csb.AppendLine("[StructLayout(LayoutKind.Explicit)]");
56+
csb.Append($"struct {c.Name}");
57+
if (!string.IsNullOrEmpty(c.Comment))
58+
{
59+
csb.Append($" // {c.Comment}");
60+
}
61+
csb.AppendLine();
62+
63+
csb.AppendLine("{");
64+
65+
csb.AppendLine(
66+
string.Join(
67+
Environment.NewLine + Environment.NewLine,
68+
YieldMemberDefinitions(c.Nodes, logger)
69+
.Select(m => $"\t{GetFieldDecorator(m)}{Environment.NewLine}\t{GetFieldDefinition(m)}")
70+
)
71+
);
72+
csb.Append("}");
73+
return csb.ToString();
74+
})
75+
)
76+
);
77+
78+
return sb.ToString();
79+
}
80+
81+
private IEnumerable<MemberDefinition> YieldMemberDefinitions(IEnumerable<BaseNode> members, ILogger logger)
82+
{
83+
Contract.Requires(members != null);
84+
Contract.Requires(Contract.ForAll(members, m => m != null));
85+
Contract.Ensures(Contract.Result<IEnumerable<MemberDefinition>>() != null);
86+
Contract.Ensures(Contract.ForAll(Contract.Result<IEnumerable<MemberDefinition>>(), d => d != null));
87+
88+
foreach (var member in members.WhereNot(n => n is BaseHexNode))
89+
{
90+
var bitFieldNode = member as BitFieldNode;
91+
if (bitFieldNode != null)
92+
{
93+
string type;
94+
switch (bitFieldNode.Bits)
95+
{
96+
default:
97+
type = typeToTypedefMap[typeof(UInt8Node)];
98+
break;
99+
case 16:
100+
type = typeToTypedefMap[typeof(UInt16Node)];
101+
break;
102+
case 32:
103+
type = typeToTypedefMap[typeof(UInt32Node)];
104+
break;
105+
case 64:
106+
type = typeToTypedefMap[typeof(UInt64Node)];
107+
break;
108+
}
109+
110+
yield return new MemberDefinition(member, type);
111+
}
112+
else
113+
{
114+
if (typeToTypedefMap.TryGetValue(member.GetType(), out var type))
115+
{
116+
yield return new MemberDefinition(member, type);
117+
}
118+
else
119+
{
120+
var generator = CustomCodeGenerator.GetGenerator(member, Language);
121+
if (generator != null)
122+
{
123+
yield return generator.GetMemberDefinition(member, Language, logger);
124+
125+
continue;
126+
}
127+
128+
logger.Log(LogLevel.Error, $"Skipping node with unhandled type: {member.GetType()}");
129+
}
130+
}
131+
}
132+
}
133+
134+
private string GetFieldDecorator(MemberDefinition member)
135+
{
136+
Contract.Requires(member != null);
137+
138+
return $"[FieldOffset({member.Offset})]";
139+
}
140+
141+
private string GetFieldDefinition(MemberDefinition member)
142+
{
143+
Contract.Requires(member != null);
144+
145+
return $"public {member.Type} {member.Name}; //0x{member.Offset:X04} {member.Comment}".Trim();
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)