Il2CppDumper icon indicating copy to clipboard operation
Il2CppDumper copied to clipboard

Wrong function signature when the class is defined as a struct

Open kotori2 opened this issue 1 year ago • 1 comments

Note: if you do not provide all of the following information I will directly ignore and close this issue

  • Il2CppDumper version 6.7.38
  • Target Unity version (optional) 2021.3.12f1
  • Describe the issue this should be a pointer even for struct class. Original definition:
namespace DefaultNamespace
{
    public struct Structure
    {
        private uint[] datas;
        private int p; 

        public Structure(uint[] _datas, int _p)
        {
            datas = _datas;
            p = _p;
        }

    }
}

Il2Cpp output:

// System.Void DefaultNamespace.Structure::.ctor(System.UInt32[],System.Int32)
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR void Structure__ctor_m6D54596E55D081B9E3821988795275D8A0540958 (Structure_t360561EF943FEF121944803824E6A238E5BADE61* __this, UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* ____datas0, int32_t ____p1, const RuntimeMethod* method) 
{
	{
		// datas = _datas;
		UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* L_0 = ____datas0;
		__this->___datas_11 = L_0;
		Il2CppCodeGenWriteBarrier((void**)(&__this->___datas_11), (void*)L_0);
		// p = _p;
		int32_t L_1 = ____p1;
		__this->___p_12 = L_1;
		// }
		return;
	}
}

Il2Cppdumper:

    {
      "Address": 1290528,
      "Name": "DefaultNamespace.Structure$$.ctor",
      "Signature": "void DefaultNamespace_Structure___ctor (DefaultNamespace_Structure_o __this, System_UInt32_array* _datas, int32_t _p, const MethodInfo* method);",
      "TypeSignature": "viiii"
    },
  • Upload executable file and global-metadata.dat It's really easy to replicate this issue with Unity project.

kotori2 avatar Mar 04 '23 22:03 kotori2

I think this rule only applies to this pointer. For other function calls / returns, it will still keep the structure in stack. Here is an example:

namespace DefaultNamespace
{
    public class StructCaller
    {
        public Structure Call()
        { 
            uint[] arr = new uint[0];
            var s = new Structure(arr, 0);
            return s;
        }

        public Structure MeaninglessPass(Structure s)
        {
            return s;
        }
    }
}
// DefaultNamespace.Structure DefaultNamespace.StructCaller::Call()
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR Structure_t360561EF943FEF121944803824E6A238E5BADE61 StructCaller_Call_m83B7AA5633ED4B24D7005681747CFC914398ADC1 (StructCaller_t1862CAAC6E3464E8DEE388A421709BC0CBE38DCF* __this, const RuntimeMethod* method) 
{
	static bool s_Il2CppMethodInitialized;
	if (!s_Il2CppMethodInitialized)
	{
		il2cpp_codegen_initialize_runtime_metadata((uintptr_t*)&UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA_il2cpp_TypeInfo_var);
		s_Il2CppMethodInitialized = true;
	}
	UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* V_0 = NULL;
	{
		// uint[] arr = new uint[0];
		UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* L_0 = (UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA*)(UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA*)SZArrayNew(UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA_il2cpp_TypeInfo_var, (uint32_t)0);
		V_0 = L_0;
		// var s = new Structure(arr, 0);
		UInt32U5BU5D_t02FBD658AD156A17574ECE6106CF1FBFCC9807FA* L_1 = V_0;
		Structure_t360561EF943FEF121944803824E6A238E5BADE61 L_2;
		memset((&L_2), 0, sizeof(L_2));
		Structure__ctor_m6D54596E55D081B9E3821988795275D8A0540958((&L_2), L_1, 0, /*hidden argument*/NULL);
		// return s;
		return L_2;
	}
}
// DefaultNamespace.Structure DefaultNamespace.StructCaller::MeaninglessPass(DefaultNamespace.Structure)
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR Structure_t360561EF943FEF121944803824E6A238E5BADE61 StructCaller_MeaninglessPass_mF7C123782870858D21D994DBEECB1C02F31BFAB5 (StructCaller_t1862CAAC6E3464E8DEE388A421709BC0CBE38DCF* __this, Structure_t360561EF943FEF121944803824E6A238E5BADE61 ___s0, const RuntimeMethod* method) 
{
	{
		// return s;
		Structure_t360561EF943FEF121944803824E6A238E5BADE61 L_0 = ___s0;
		return L_0;
	}
}

kotori2 avatar Mar 04 '23 22:03 kotori2