コード例 #1
0
        public unsafe static bool niecmod_script_copy_ptr_methed_to_methed_internal <T>(IntPtr method_ptr_a, IntPtr method_ptr_t, bool copy_methed_info)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                throw new NotSupportedException("Sims 3 64 bit version not supported.");
            }

#if !GameVersion_0_Release_2_0_209
            throw new NotSupportedException("Game versions not supported. Only Patch 1.67.2");
#else
            if (method_ptr_a.value == null || method_ptr_t.value == null)
            {
                return(false);
            }

            uint ptr_a = (uint)method_ptr_a.value;
            uint ptr_t = (uint)method_ptr_t.value;

            //if (ptr_a == ptr_t)
            //{
            //    NFinalizeDeath.AssertX(false, "script_copy_ptr_methed_to_methed_internal\nif (ptr_a == ptr_t) ST:\n" + NDebugger.CurrentStackLite());
            //    return false;
            //}

            if (*(uint *)(ptr_a) == 0x00000000)
            {
                NFinalizeDeath.AssertX
                    (false, "*(uint*)(ptr_a) == 0x00000000\nStackTrace:\n" + NDebugger.GetCurrentStackLite());
                return(false);
            }

            if (*(uint *)(ptr_t) == *(uint *)(ptr_a))
            {
                return(true);
            }

            *(uint *)(ptr_t)       = *(uint *)(ptr_a);       // IL list runtime IP
            *(uint *)(ptr_t + 0x4) = *(uint *)(ptr_a + 0x4); // info method virtaul?

            if (copy_methed_info)
            {
                *(uint *)(ptr_t + 0x8) = *(uint *)(ptr_a + 0x8); // info method if not pre link?
                *(uint *)(ptr_t + 0xC) = *(uint *)(ptr_a + 0xC); // info method virtaul? if created?
            }
            else if (*(uint *)(ptr_t + 0xC) == 0x00000000)
            {
                *(uint *)(ptr_t + 0xC) = *(uint *)(ptr_t + 0x8); // info method virtaul? if created? or info method if not pre link?
            }

            *(uint *)(ptr_t + 0x10) = *(uint *)(ptr_a + 0x10); // Unknown

            *(uint *)(ptr_t + 0x14) = *(uint *)(ptr_a + 0x14); // set filend? by sfsfld or newobj
            *(uint *)(ptr_t + 0x18) = *(uint *)(ptr_a + 0x18); // set filend? by sfsfld or newobj

            *(uint *)(ptr_t + 0x1C) = *(uint *)(ptr_a + 0x1C); // IL call method?
            *(uint *)(ptr_t + 0x20) = *(uint *)(ptr_a + 0x20); // IL call method?

            *(uint *)(ptr_t + 0x24) = *(uint *)(ptr_a + 0x24); // Unknown
            *(uint *)(ptr_t + 0x28) = *(uint *)(ptr_a + 0x28); // Unknown
            *(uint *)(ptr_t + 0x2C) = *(uint *)(ptr_a + 0x2C); // Unknown

            *(uint *)(ptr_t + 0x30) = *(uint *)(ptr_a + 0x30); // Unknown
            *(uint *)(ptr_t + 0x34) = *(uint *)(ptr_a + 0x34); // count?

            *(uint *)(ptr_t + 0x38) = *(uint *)(ptr_a + 0x38); // Unknown
            *(uint *)(ptr_t + 0x3C) = *(uint *)(ptr_a + 0x3C); // Unknown
            *(uint *)(ptr_t + 0x40) = *(uint *)(ptr_a + 0x40); // Unknown count?
            *(uint *)(ptr_t + 0x44) = *(uint *)(ptr_a + 0x44); // created or not created flag

            return(true);
#endif // GameVersion_0_Release_2_0_209
        }
コード例 #2
0
 public static void Assert(string message)
 {
     NFinalizeDeath.AssertX(false, message);
 }
コード例 #3
0
        public unsafe static bool niecmod_script_copy_ptr_func_to_func(MethodBase a, MethodBase t, bool prelink, bool check, bool shouldThrowOnFailure, bool copy_methed_info)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                if (shouldThrowOnFailure)
                {
                    throw new NotSupportedException("Sims 3 64 bit version not supported.");
                }
                return(false);
            }

#if !GameVersion_0_Release_2_0_209
            throw new NotSupportedException("Game versions not supported. Only Patch 1.67.2");
#else
            niec_native_func.OutputDebugString("niecmod_script_copy_ptr_func_to_func(...) called");


            if (a == null)
            {
                if (shouldThrowOnFailure)
                {
                    throw new ArgumentNullException("a");
                }
                return(false);
            }

            if (t == null)
            {
                if (shouldThrowOnFailure)
                {
                    throw new ArgumentNullException("t");
                }
                return(false);
            }

            if (t == a)
            {
                NFinalizeDeath.AssertX(false, "script_copy_ptr_func_to_func: if (t == a) ST:\n" + NDebugger.GetCurrentStackLite());
                return(false);
            }

            niec_native_func.OutputDebugString("Name A: " + a.DeclaringType.FullName + "." + a.Name + " | IsGeneric: " + a.IsGenericMethod + " | Type: " + a.GetType().ToString());
            niec_native_func.OutputDebugString("Name T: " + t.DeclaringType.FullName + "." + t.Name + " | IsGeneric: " + t.IsGenericMethod + " | Type: " + t.GetType().ToString());

            uint tuint;

            if (sCheckMethodChecksum != null)
            {
                if (t is MonoMethod && sCheckMethodChecksum.TryGetValue(((MonoMethod)t).mhandle, out tuint))
                {
                    return(false);
                }
                if (t is MonoCMethod && sCheckMethodChecksum.TryGetValue(((MonoCMethod)t).mhandle, out tuint))
                {
                    return(false);
                }
            }

            uint au = 0;
            uint tu = 0;

            try
            {
                //niec_native_func.OutputDebugString("calling GetMethodImplementationFlags");
                //a.GetMethodImplementationFlags();
                //niec_native_func.OutputDebugString("calling GetParameters");
                //a.GetParameters();
                //niec_native_func.OutputDebugString("calling GetMethodImplementationFlags T");
                //t.GetMethodImplementationFlags();
                //niec_native_func.OutputDebugString("calling GetParameters T");
                //t.GetParameters();
                //
                //niec_native_func.OutputDebugString("calling NFinalizeDeath.M(a.Attributes)");
                //NFinalizeDeath.M(a.Attributes);
                //niec_native_func.OutputDebugString("calling NFinalizeDeath.M(t.Attributes)");
                //NFinalizeDeath.M(t.Attributes);

                if (t is MonoMethod)
                {
                    niec_native_func.OutputDebugString("calling ScriptCore.TaskControl.GetMethodChecksum(t.MethodHandle, out tu);");
                    ScriptCore.TaskControl.TaskControl_GetMethodChecksum(((MonoMethod)t).mhandle, out tu);
                    niec_native_func.OutputDebugString("tu: 0x" + tu.ToString("X"));
                }
                else if (t is MonoCMethod)
                {
                    niec_native_func.OutputDebugString("calling ScriptCore.TaskControl.GetMethodChecksum(t.MethodHandle, out tu);");
                    ScriptCore.TaskControl.TaskControl_GetMethodChecksum(((MonoCMethod)t).mhandle, out tu);
                    niec_native_func.OutputDebugString("tu: 0x" + tu.ToString("X"));
                }

                if (a is MonoMethod)
                {
                    niec_native_func.OutputDebugString("calling ScriptCore.TaskControl.GetMethodChecksum(a.MethodHandle, out au);");
                    ScriptCore.TaskControl.TaskControl_GetMethodChecksum(((MonoMethod)a).mhandle, out au);
                    niec_native_func.OutputDebugString("au: 0x" + au.ToString("X"));
                }
                else if (a is MonoCMethod)
                {
                    niec_native_func.OutputDebugString("calling ScriptCore.TaskControl.GetMethodChecksum(a.MethodHandle, out au);");
                    ScriptCore.TaskControl.TaskControl_GetMethodChecksum(((MonoCMethod)a).mhandle, out au);
                    niec_native_func.OutputDebugString("au: 0x" + au.ToString("X"));
                }
            }
            catch (Exception)
            { }

            if (a is ConstructorInfo && t is ConstructorInfo)
            {
                niec_native_func.OutputDebugString("a && t is System.Reflection.ConstructorInfo");

                var cah = ((MonoCMethod)a).mhandle;
                var cth = ((MonoCMethod)t).mhandle;

                niec_native_func.OutputDebugString("cahandle: " + ((uint)cah).ToString("X"));
                niec_native_func.OutputDebugString("cthandle: " + ((uint)cth).ToString("X"));

                if (cah == null || cth == null)
                {
                    niec_native_func.OutputDebugString("if (cah == null || cth == null)");
                    return(false);
                }

                uint camethod_ptr = *(uint *)((uint)cah + 0x14);
                uint ctmethod_ptr = *(uint *)((uint)cth + 0x14);

                niec_native_func.OutputDebugString("amethod_ptr: " + camethod_ptr.ToString("X"));
                niec_native_func.OutputDebugString("ctmethod_ptr: " + ctmethod_ptr.ToString("X"));

                if (camethod_ptr == 0 || camethod_ptr == 0xAA || ctmethod_ptr == 0 || ctmethod_ptr == 0xAA)
                {
                    niec_native_func.OutputDebugString("if (camethod_ptr == 0 || camethod_ptr == 0xAA || ctmethod_ptr == 0 || ctmethod_ptr == 0xAA)");
                    return(false);
                }

                var r = niecmod_script_copy_ptr_methed_to_methed_internal <ConstructorInfo>(
                    new IntPtr()
                {
                    value = (void *)camethod_ptr
                },
                    new IntPtr()
                {
                    value = (void *)ctmethod_ptr
                },
                    copy_methed_info
                    );

                if (r && sCheckMethodChecksum != null)
                {
                    sCheckMethodChecksum.Add(((MonoCMethod)t).mhandle, (au * (20 & 15 / au + 0x50) + 30));
                }

                niec_native_func.OutputDebugString("copy_ptr_methed_to_methed_internal: " + r);
                niec_native_func.OutputDebugString("niecmod_script_copy_ptr_func_to_func(...) Done!");

                return(r);
            }

            try
            {
                if (check)
                {
                    if (a is MethodInfo && t is MethodInfo)
                    {
                        if (!niecmod_script_check_func_e_func((MethodInfo)a, (MethodInfo)t, shouldThrowOnFailure))
                        {
                            niec_native_func.OutputDebugString("niecmod_script_check_func_e_func(a, t, shouldThrowOnFailure) failed");
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (shouldThrowOnFailure)
                {
                    niec_native_func.OutputDebugString(ex.Message);
                }
                throw;
            }


            var ah = ((MonoMethod)a).mhandle;
            var th = ((MonoMethod)t).mhandle;

            niec_native_func.OutputDebugString("ahandle: " + ((uint)ah).ToString("X"));
            niec_native_func.OutputDebugString("thandle: " + ((uint)th).ToString("X"));

            if (ah == null || th == null)
            {
                niec_native_func.OutputDebugString("if (ah == null || th == null)");
                return(false);
            }

            if (prelink)
            {
                try
                {
                    niec_native_func.OutputDebugString("calling MethodInfo.GetMethodBody(ah)");
                    MethodInfo.GetMethodBody(ah);
                    niec_native_func.OutputDebugString("calling MethodInfo.GetMethodBody(th)");
                    MethodInfo.GetMethodBody(th);
                }
                catch (Exception)
                { }

                try
                {
                    if (a is MethodInfo)
                    {
                        niec_native_func.OutputDebugString("calling MethodInfo:Prelink A");//: Methed Name: " + a.Name + " | IsGenericMethod: " + a.IsGenericMethod);
                        System.Runtime.InteropServices.Marshal.Prelink((MethodInfo)a);
                    }
                    if (t is MethodInfo)
                    {
                        niec_native_func.OutputDebugString("calling MethodInfo:Prelink T");//: Methed Name: " + t.Name + " | IsGenericMethod: " + t.IsGenericMethod);
                        System.Runtime.InteropServices.Marshal.Prelink((MethodInfo)t);
                    }
                }
                catch (Exception)
                {
                    niec_native_func.OutputDebugString("Prelink failed");

                    if (shouldThrowOnFailure)
                    {
                        throw;
                    }

                    return(false);
                }
            }

            uint amethod_ptr = *(uint *)((uint)ah + 0x14);
            uint tmethod_ptr = *(uint *)((uint)th + 0x14);

            niec_native_func.OutputDebugString("amethod_ptr: " + amethod_ptr.ToString("X"));
            niec_native_func.OutputDebugString("tmethod_ptr: " + tmethod_ptr.ToString("X"));

            if (amethod_ptr == 0 || amethod_ptr == 0xAA || tmethod_ptr == 0 || tmethod_ptr == 0xAA)
            {
                niec_native_func.OutputDebugString("if (amethod_ptr == 0 || amethod_ptr == 0xAA || tmethod_ptr == 0 || tmethod_ptr == 0xAA)");
                return(false);
            }

            var tx = niecmod_script_copy_ptr_methed_to_methed_internal <niec_script_func> (
                new IntPtr()
            {
                value = (void *)amethod_ptr
            },
                new IntPtr()
            {
                value = (void *)tmethod_ptr
            },
                copy_methed_info
                );

            if (tx && sCheckMethodChecksum != null)
            {
                sCheckMethodChecksum.Add(((MonoMethod)t).mhandle, (au * (50 & 10 / au + 5) + 20));
            }

            niec_native_func.OutputDebugString("copy_ptr_methed_to_methed_internal: " + tx);
            niec_native_func.OutputDebugString("niecmod_script_copy_ptr_func_to_func(...) Done!");

            return(tx);
#endif // GameVersion_0_Release_2_0_209
        }