diff --git a/source/Indy.IL2CPU.IL/OpCodeMap.cs b/source/Indy.IL2CPU.IL/OpCodeMap.cs index 06963f259..00e514417 100644 --- a/source/Indy.IL2CPU.IL/OpCodeMap.cs +++ b/source/Indy.IL2CPU.IL/OpCodeMap.cs @@ -107,6 +107,27 @@ namespace Indy.IL2CPU.IL { return sb.ToString().TrimEnd(',') + ")"; } + /// + /// Gets the full name of a method, without the defining type included + /// + /// + /// + private static string GetStrippedMethodDefinitionFullName(MethodReference aSelf) { + StringBuilder sb = new StringBuilder(aSelf.ReturnType.ReturnType.FullName + " " + aSelf.Name); + sb.Append("("); + if (aSelf.HasThis) { + sb.Append(aSelf.DeclaringType.FullName); + sb.Append(","); + } + if (aSelf.Parameters.Count > 0) { + foreach (ParameterDefinition xParam in aSelf.Parameters) { + sb.Append(xParam.ParameterType.FullName); + sb.Append(","); + } + } + return sb.ToString().TrimEnd(',') + ")"; + } + private void InitializePlugMethodsList(Assembler.Assembler aAssembler, IEnumerable aPlugs, Func aTypeResolver, Func aAssemblyResolver) { if (mPlugMethods != null) { throw new Exception("PlugMethods list already initialized!"); @@ -145,7 +166,6 @@ namespace Indy.IL2CPU.IL { CustomAttribute xPlugMethodAttrib = (from item in xMethod.CustomAttributes.Cast() where item.Constructor.DeclaringType.FullName == typeof(PlugMethodAttribute).FullName select item).FirstOrDefault(); - //System.Diagnostics.Debugger.Break(); string xSignature = String.Empty; if (xPlugMethodAttrib != null) { if (!xPlugMethodAttrib.Resolved) { @@ -172,15 +192,15 @@ namespace Indy.IL2CPU.IL { continue; } } - string xStrippedSignature = GetMethodDefinitionFullName(xMethod).Replace(xType.FullName, ""); + string xStrippedSignature = GetStrippedMethodDefinitionFullName(xMethod); foreach (MethodDefinition xOrigMethodDef in xReplaceTypeDef.Methods) { - string xOrigStrippedSignature = GetMethodDefinitionFullName(xOrigMethodDef).Replace(xReplaceTypeDef.FullName, ""); + string xOrigStrippedSignature = GetStrippedMethodDefinitionFullName(xOrigMethodDef); if (xOrigStrippedSignature == xStrippedSignature) { mPlugMethods.Add(Label.GenerateLabelName(xOrigMethodDef), xMethod); } } foreach (MethodDefinition xOrigMethodDef in xReplaceTypeDef.Constructors) { - string xOrigStrippedSignature = GetMethodDefinitionFullName(xOrigMethodDef).Replace(xReplaceTypeDef.FullName, ""); + string xOrigStrippedSignature = GetStrippedMethodDefinitionFullName(xOrigMethodDef); if (xOrigStrippedSignature == xStrippedSignature) { mPlugMethods.Add(Label.GenerateLabelName(xOrigMethodDef), xMethod); } diff --git a/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs b/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs index 2ca9c8d14..7d0cbc115 100644 --- a/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs +++ b/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs @@ -3,16 +3,20 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; +using Indy.IL2CPU.Plugs; namespace Indy.IL2CPU.CustomImplementation.System { + [Plug(Target = typeof(String))] public static class StringImpl { [MethodAlias(Name = "System.String System.String.FastAllocateString(System.Int32)")] + [PlugMethod(Enabled = false)] public static String FastAllocateString(int aLength) { Char[] xItems = new Char[aLength]; return new String(xItems); } [MethodAlias(Name = "System.Void System.String..ctor(System.Char[],System.Int32,System.Int32)")] + [PlugMethod(Enabled = false)] public static void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")]ref Char[] aStorage, Char[] aChars, int aStartIndex, int aLength) { Char[] newChars = new Char[aLength]; Array.Copy(aChars, aStartIndex, newChars, 0, aLength); @@ -20,10 +24,21 @@ namespace Indy.IL2CPU.CustomImplementation.System { } [MethodAlias(Name = "System.Void System.String..ctor(System.Char[])")] + [PlugMethod(Enabled = false)] public static void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")] ref Char[] aStorage, Char[] aChars) { aStorage = aChars; } + public static int IndexOf(string aThis, char c) { + for (int i = 0; i < aThis.Length; i++) { + if (aThis[i] == c) { + return i; + } + } + return -1; + } + + [PlugMethod(Enabled = false)] public static uint GetStorage(string aString) { return 0; }