Skip to content

Commit

Permalink
Fix Invalid Generic Parameter Names
Browse files Browse the repository at this point in the history
  • Loading branch information
ds5678 committed Sep 14, 2024
1 parent 89b8d31 commit 847f46e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Il2CppInterop.Generator/Contexts/MethodRewriteContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public MethodRewriteContext(TypeRewriteContext declaringType, MethodDefinition o
var genericParameter = new GenericParameter(oldParameter.Name);
genericParameter.Attributes = oldParameter.Attributes.StripValueTypeConstraint();
newMethod.GenericParameters.Add(genericParameter);

if (genericParameter.Name.IsInvalidInSource())
genericParameter.Name = genericParameter.Name.FilterInvalidInSourceChars();
}
}

Expand Down Expand Up @@ -135,6 +138,8 @@ public void CtorPhase2()
{
var oldParameter = genericParams[index];
var genericParameter = new GenericParameter(oldParameter.Name);
if (genericParameter.Name.IsInvalidInSource())
genericParameter.Name = genericParameter.Name.FilterInvalidInSourceChars();
genericMethodInfoStoreType.GenericParameters.Add(genericParameter);
selfSubstRef.TypeArguments.Add(genericParameter.ToTypeSignature());
var newParameter = NewMethod.GenericParameters[index];
Expand Down
3 changes: 3 additions & 0 deletions Il2CppInterop.Generator/Contexts/RewriteGlobalContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public AssemblyRewriteContext GetAssemblyByName(string name)
{
var newGenericParameter = new GenericParameter(genericParameter.Name, genericParameter.Attributes);

if (newGenericParameter.Name.IsInvalidInSource())
newGenericParameter.Name = newGenericParameter.Name.FilterInvalidInSourceChars();

foreach (var constraint in genericParameter.Constraints)
{
var newConstraintType = constraint.Constraint != null ? resolve(constraint.Constraint.ToTypeSignature())?.ToTypeDefOrRef() : null;
Expand Down
2 changes: 2 additions & 0 deletions Il2CppInterop.Generator/Passes/Pass12FillTypedefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public static void DoPass(RewriteGlobalContext context)
foreach (var originalParameter in typeContext.OriginalType.GenericParameters)
{
var newParameter = new GenericParameter(originalParameter.Name);
if (newParameter.Name.IsInvalidInSource())
newParameter.Name = newParameter.Name.FilterInvalidInSourceChars();
typeContext.NewType.GenericParameters.Add(newParameter);
newParameter.Attributes = originalParameter.Attributes.StripValueTypeConstraint();
}
Expand Down

0 comments on commit 847f46e

Please sign in to comment.