add initial support for required forward references in il2cpp types, also fix issues with type names clashing with il2cpp api types
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -5,9 +5,6 @@
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Il2CppInspector.Cpp
|
namespace Il2CppInspector.Cpp
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -65,9 +62,9 @@ namespace Il2CppInspector.Cpp
|
|||||||
// Uniquely name an object within the parent namespace
|
// Uniquely name an object within the parent namespace
|
||||||
public string GetName(T t) {
|
public string GetName(T t) {
|
||||||
// If we've named this particular object before, just return that name
|
// If we've named this particular object before, just return that name
|
||||||
string name;
|
if (names.TryGetValue(t, out var name))
|
||||||
if (names.TryGetValue(t, out name))
|
|
||||||
return name;
|
return name;
|
||||||
|
|
||||||
// Obtain the mangled name for the object
|
// Obtain the mangled name for the object
|
||||||
name = keyFunc(t);
|
name = keyFunc(t);
|
||||||
// Check if the mangled name has been given to another object - if it has,
|
// Check if the mangled name has been given to another object - if it has,
|
||||||
|
|||||||
@@ -456,4 +456,14 @@ namespace Il2CppInspector.Cpp
|
|||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CppForwardDefinitionType : CppType
|
||||||
|
{
|
||||||
|
public CppForwardDefinitionType(string name) : base(name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString(string format = "") => $"struct {Name};";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,11 @@
|
|||||||
All rights reserved.
|
All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using Il2CppInspector.Cpp.UnityHeaders;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Il2CppInspector.Cpp.UnityHeaders;
|
|
||||||
|
|
||||||
namespace Il2CppInspector.Cpp
|
namespace Il2CppInspector.Cpp
|
||||||
{
|
{
|
||||||
@@ -23,7 +19,7 @@ namespace Il2CppInspector.Cpp
|
|||||||
public Dictionary<string, CppType> Types { get; }
|
public Dictionary<string, CppType> Types { get; }
|
||||||
|
|
||||||
// All of the literal typedef aliases
|
// All of the literal typedef aliases
|
||||||
public Dictionary<string, CppType> TypedefAliases { get; } = new Dictionary<string, CppType>();
|
public Dictionary<string, CppType> TypedefAliases { get; } = [];
|
||||||
|
|
||||||
public CppType this[string s] => Types.ContainsKey(s)? Types[s] :
|
public CppType this[string s] => Types.ContainsKey(s)? Types[s] :
|
||||||
TypedefAliases.ContainsKey(s)? TypedefAliases[s].AsAlias(s) : null;
|
TypedefAliases.ContainsKey(s)? TypedefAliases[s].AsAlias(s) : null;
|
||||||
@@ -34,7 +30,8 @@ namespace Il2CppInspector.Cpp
|
|||||||
// Architecture width in bits (32/64) - to determine pointer sizes
|
// Architecture width in bits (32/64) - to determine pointer sizes
|
||||||
public int WordSize { get; }
|
public int WordSize { get; }
|
||||||
|
|
||||||
private Dictionary<string, ComplexValueType> complexTypeMap = new Dictionary<string, ComplexValueType> {
|
private Dictionary<string, ComplexValueType> complexTypeMap = new()
|
||||||
|
{
|
||||||
["struct"] = ComplexValueType.Struct,
|
["struct"] = ComplexValueType.Struct,
|
||||||
["union"] = ComplexValueType.Union,
|
["union"] = ComplexValueType.Union,
|
||||||
["enum"] = ComplexValueType.Enum
|
["enum"] = ComplexValueType.Enum
|
||||||
@@ -44,22 +41,23 @@ namespace Il2CppInspector.Cpp
|
|||||||
private string currentGroup = string.Empty;
|
private string currentGroup = string.Empty;
|
||||||
public void SetGroup(string group) => currentGroup = group;
|
public void SetGroup(string group) => currentGroup = group;
|
||||||
|
|
||||||
private static readonly List<CppType> primitiveTypes = new List<CppType> {
|
private static readonly List<CppType> primitiveTypes =
|
||||||
new CppType("uint8_t", 8),
|
[
|
||||||
new CppType("uint16_t", 16),
|
new("uint8_t", 8),
|
||||||
new CppType("uint32_t", 32),
|
new("uint16_t", 16),
|
||||||
new CppType("uint64_t", 64),
|
new("uint32_t", 32),
|
||||||
new CppType("int8_t", 8),
|
new("uint64_t", 64),
|
||||||
new CppType("int16_t", 16),
|
new("int8_t", 8),
|
||||||
new CppType("int32_t", 32),
|
new("int16_t", 16),
|
||||||
new CppType("int64_t", 64),
|
new("int32_t", 32),
|
||||||
new CppType("char", 8),
|
new("int64_t", 64),
|
||||||
new CppType("int", 32),
|
new("char", 8),
|
||||||
new CppType("float", 32),
|
new("int", 32),
|
||||||
new CppType("double", 64),
|
new("float", 32),
|
||||||
new CppType("bool", 8),
|
new("double", 64),
|
||||||
new CppType("void", 0)
|
new("bool", 8),
|
||||||
};
|
new("void", 0)
|
||||||
|
];
|
||||||
|
|
||||||
public CppTypeCollection(int wordSize) {
|
public CppTypeCollection(int wordSize) {
|
||||||
if (wordSize != 32 && wordSize != 64)
|
if (wordSize != 32 && wordSize != 64)
|
||||||
@@ -538,15 +536,18 @@ namespace Il2CppInspector.Cpp
|
|||||||
public CppComplexType Struct(string name = "", int alignmentBytes = 0) {
|
public CppComplexType Struct(string name = "", int alignmentBytes = 0) {
|
||||||
if (!string.IsNullOrEmpty(name) && Types.TryGetValue(name, out var cppType))
|
if (!string.IsNullOrEmpty(name) && Types.TryGetValue(name, out var cppType))
|
||||||
return (CppComplexType) cppType;
|
return (CppComplexType) cppType;
|
||||||
|
|
||||||
var type = new CppComplexType(ComplexValueType.Struct) {Name = name, Group = currentGroup, AlignmentBytes = alignmentBytes};
|
var type = new CppComplexType(ComplexValueType.Struct) {Name = name, Group = currentGroup, AlignmentBytes = alignmentBytes};
|
||||||
if (!string.IsNullOrEmpty(name))
|
if (!string.IsNullOrEmpty(name))
|
||||||
Add(type);
|
Add(type);
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CppComplexType Union(string name = "", int alignmentBytes = 0) {
|
public CppComplexType Union(string name = "", int alignmentBytes = 0) {
|
||||||
if (!string.IsNullOrEmpty(name) && Types.TryGetValue(name, out var cppType))
|
if (!string.IsNullOrEmpty(name) && Types.TryGetValue(name, out var cppType))
|
||||||
return (CppComplexType) cppType;
|
return (CppComplexType) cppType;
|
||||||
|
|
||||||
var type = new CppComplexType(ComplexValueType.Union) {Name = name, Group = currentGroup, AlignmentBytes = alignmentBytes};
|
var type = new CppComplexType(ComplexValueType.Union) {Name = name, Group = currentGroup, AlignmentBytes = alignmentBytes};
|
||||||
if (!string.IsNullOrEmpty(name))
|
if (!string.IsNullOrEmpty(name))
|
||||||
Add(type);
|
Add(type);
|
||||||
@@ -554,9 +555,13 @@ namespace Il2CppInspector.Cpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CppEnumType Enum(CppType underlyingType, string name = "") {
|
public CppEnumType Enum(CppType underlyingType, string name = "") {
|
||||||
|
if (!string.IsNullOrEmpty(name) && Types.TryGetValue(name, out var cppType))
|
||||||
|
return (CppEnumType)cppType;
|
||||||
|
|
||||||
var type = new CppEnumType(underlyingType) {Name = name, Group = currentGroup};
|
var type = new CppEnumType(underlyingType) {Name = name, Group = currentGroup};
|
||||||
if (!string.IsNullOrEmpty(name))
|
if (!string.IsNullOrEmpty(name))
|
||||||
Add(type);
|
Add(type);
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,11 +590,17 @@ namespace Il2CppInspector.Cpp
|
|||||||
cppTypes.AddFromDeclarationText(apis);
|
cppTypes.AddFromDeclarationText(apis);
|
||||||
|
|
||||||
// Don't allow any of the header type names or primitive type names to be re-used
|
// Don't allow any of the header type names or primitive type names to be re-used
|
||||||
foreach (var type in cppTypes.Types.Values)
|
foreach (var type in cppTypes.Types.Keys)
|
||||||
declGen?.TypeNamespace.TryReserveName(type.Name);
|
{
|
||||||
|
declGen?.TypeNamespace.TryReserveName(type);
|
||||||
|
declGen?.GlobalsNamespace.TryReserveName(type);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var typedef in cppTypes.TypedefAliases.Values)
|
foreach (var typedef in cppTypes.TypedefAliases.Keys)
|
||||||
declGen?.GlobalsNamespace.TryReserveName(typedef.Name);
|
{
|
||||||
|
declGen?.TypeNamespace.TryReserveName(typedef);
|
||||||
|
declGen?.GlobalsNamespace.TryReserveName(typedef);
|
||||||
|
}
|
||||||
|
|
||||||
cppTypes.SetGroup("");
|
cppTypes.SetGroup("");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user