Open burnedram opened 11 months ago
Hi. Sorry for pinging.
I've found this issue based on the exception message I get for Canvas.renderMode
in an Unity 2023.1.9f1 IL2CPP translated game.
Since this PR isn't merged and isn't released with the BepInEx nightly, how can I try these changes to see if it fixes my problem?
Edit
Okay, figured it out. Checkout your fork, build.bat, open the BepInEx\core and replace the 4 IL2CppInterop dll of the nightly build with the various generated new dlls. Reset the BepInEx install, run the game. Now I got the method above not throwing by itself, but now I get a different runtime exception:
set_renderMode_Injected(MarshalledUnityObject.MarshalNullCheck((_0021_00210)this), value);
System.MissingMethodException: Method not found: 'IntPtr MarshalledUnityObject.MarshalNullCheck(!!0)'.
at UnityEngine.Canvas.set_renderMode(RenderMode value)
Edit 2
Managed to get it working. I have to manually call that inject method with a properly cast target object:
var panel = new GameObject("MyOverlay");
var canvas = panel.AddComponent<Canvas>();
canvas.sortingOrder = 1000;
Canvas.set_renderMode_Injected(
MarshalledUnityObject.MarshalNullCheck(canvas),
RenderMode.ScreenSpaceOverlay
);
What
"Method unstripping failed"
Why
I'm creating a Il2Cpp plugin for Dave the Diver and wanted to use IMGUI, and came across a few
"Method unstripping failed"
.So I set out to find the reason why those methods I needed didn't work and this is the result.
Translation logging
"Method unstripping failed"
is a very opaque error.This PR adds logging (to disk only) to the translation process describing why a method couldn't be translated:
The logging is saved as a
.json.gz
in theoutput
's parent folder.(I.e. it is saved in the same folder that BepInEx saves
LogOutput.log
)I choose json because it is very easy to use tools such as
jq
to query the rather large amount of methods that can't be translated currently.Examples
Excerpt
Logs from my development
The entire log file before I made any fixes/changes: unstrip_original.json.gz Summary of error categories:
The entire log file with all commits in this PR: unstrip.json.gz Summary of error categories:
These logs are of course very specific to the game and Unity version I've been using, but they document the progress that I've made.
Results
Il2CppInterop now correctly translates the IMGUI methods I need in Dave The Diver v1.0.0.1055.steam! That were the metrics I went by atleast, but there's a whole slew of methods that now work correctly, including:
string
was used for aSystem.Object
parameter. (E.g. any method callingDebug.Log
and associates)System.Object
is (and was) translated intoIl2CppSystem.Object
, butstring
is obviously not such an object. AIl2CppSystem.String::op_Implicit(string)
is injected after the instruction responsible for thestring
stack object.+
is compiled into this. E.g."test" + 1 + "array"
becomes:string.Concat(new string[] {[0] = "test", [1] = 1.ToString(), [2] = "array"})
Thesetelem
instruction family only works an actual arrays (e.g.string[]
), but all arrays are translated into one ofIl2CppReferenceArray<T>
Il2CppStructArray<T>
Il2CppStringArray
Thussetelem
should be translated intocallvirt instance Il2CppBaseArray<T>::set_Item(int, T)
Il2CppStringArray
and correctly fill it with items,string.Concat(string[])
still takes astring[]
. Fixed by translating method calls on primitive and string types to redirect them to the Il2Cpp equivalent, e.g:Il2CppSystem.String.Concat(Il2CppStringArray)
Additionally, I've added some
box
/unbox
support,ld(s)flda
support, and branch retargeting tracking. The branch retargeting was mostly working before, but it was mostly coincidental. This PR allows branch targets to be a completely different instruction (which is very common due to the processes being a translation), and it allows us to emit/insert more that one instruction in the new method and still keep the branches intact.I more than welcome any comments, as I have many assumptions on how the library is supposed to work!