Пример #1
0
        public static bool niecmod_script_set_custom_native_function2(MethodInfo internal_function, uint p_func_address)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(false);
            }
#if GameVersion_0_Release_2_0_209
            var vfunc = internal_function as MonoMethod;
            if (vfunc == null)
            {
                return(false);
            }

            if (vfunc.mhandle == emtpyptr)
            {
                return(false);
            }

            uint func_address = ((uint)vfunc.mhandle.ToInt32()) + 0x20u;
            global::System.Runtime.InteropServices.Marshal.WriteInt32(new IntPtr((int)func_address), (int)p_func_address);
            return(true);
#else
            return(false);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #2
0
        public static object niecmod_script_get_obj_adderess(object obj)
        {
            bool gameIs64 = NFinalizeDeath.GameIs64Bit(false);

            try
            {
                throw new Exception("");
            }
            catch (Exception ex)
            {
                var s  = "niecmod_script_get_obj_adderess (object) ([";
                var st = ex.StackTrace;
                if (st == null || st.Length == 0)
                {
                    return(0);
                }

                int index = st.IndexOf(s);
                if (index == -1)
                {
                    return(0);
                }

                if ((index + s.Length) > st.length - (gameIs64 ? 16 : 8))
                {
                    return(0);
                }

                return(gameIs64 ?
                       ulong.Parse(st.Substring(index + s.Length, 16) ?? "0", System.Globalization.NumberStyles.AllowHexSpecifier) :
                       uint.Parse(st.Substring(index + s.Length, 8) ?? "0", System.Globalization.NumberStyles.AllowHexSpecifier));
            }
        }
Пример #3
0
        public static uint niecmod_script_get_func_ptr2(MethodInfo internal_function)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(0);
            }
#if GameVersion_0_Release_2_0_209
            var vfunc = internal_function as MonoMethod;
            if (vfunc == null)
            {
                return(0);
            }

            if (vfunc.mhandle == emtpyptr)
            {
                return(0);
            }

            uint func_address = ((uint)vfunc.mhandle.ToInt32()) + 0x20u;

            try
            {
                return((uint)global::System.Runtime.InteropServices.Marshal.ReadInt32(new IntPtr((int)func_address)));
            }
            catch (NullReferenceException)
            {
                return(0);
            }
#else
            return(0);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #4
0
        public unsafe static IntPtr niecmod_script_get_type_ptr2 <T>()
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(new IntPtr(0));
            }
#if GameVersion_0_Release_2_0_209
            var type = typeof(T);
            if (type == null || type._impl.value == null)
            {
                return(new IntPtr(0));
            }

            uint t = *(uint *)((uint)type._impl.value + 0x18);
            if (t == 0x00000000) // not created
            {
                return(new IntPtr(0));
            }

            uint y = *(uint *)(t + 0x4);

            if (y == 0xFFFF0000)
            {
                return(new IntPtr(0));
            }

            return(new IntPtr()
            {
                value = (void *)y
            });
#else
            return(new IntPtr(0));
#endif
        }
Пример #5
0
        public unsafe static uint niecmod_safecall_script_get_func_ptr(IntPtr funcHandle)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(0);
            }

#if GameVersion_0_Release_2_0_209
            if (funcHandle.value == null)
            {
                return(0);
            }

            uint r = 0;

            NFinalizeDeath.SafeCall(() =>
            {
                r = *(uint *)((uint)funcHandle.value) + 0x20u;
            });

            return(r);
#else
            return(0);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #6
0
 public static uint niecmod_script_get_str_data_address(string str)
 {
     if (NFinalizeDeath.GameIs64Bit(false))
     {
         return(0);
     }
     return((uint)str.obj_address() + (uint)System.Runtime.CompilerServices.RuntimeHelpers.OffsetToStringData);
 }
Пример #7
0
 public static uint niecmod_script_str_safe_maxaddress(string str)
 {
     if (NFinalizeDeath.GameIs64Bit(false))
     {
         throw new InvalidOperationException("Sims 3 (64 bit)!");
     }
     if (str.Length == 0)
     {
         throw new ArgumentException();
     }
     return((uint)((niecmod_script_get_str_data_address(str) + (uint)(str.Length * 2)) - System.Runtime.CompilerServices.RuntimeHelpers.OffsetToStringData));
 }
Пример #8
0
        public unsafe static int niecmod_script_size_str_utf16_to_ansi(string str) // untested
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                throw new InvalidOperationException("Sims 3 (64 bit)!");
            }

            uint *at  = (uint *)((int)str.obj_address()) + 0x8;
            var   tem = 0;

            while (*(short *)((uint *)at++) != (short)0x0000)
            {
                tem++;
            }

            return(tem);
        }
Пример #9
0
        public static bool niecmod_script_set_custom_native_function_dll(IntPtr internal_function, uint p_func_address)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(false);
            }

            if (internal_function == emtpyptr)
            {
                return(false);
            }

            var p  = niecmod_script_set_custom_native_function_dlln_created(internal_function, p_func_address);
            var p1 = niecmod_script_set_custom_native_function_dll_created(internal_function, p_func_address);

            return(p || p1);
        }
Пример #10
0
        public unsafe static uint niecmod_script_get_func_ptr(IntPtr funcHandle)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(0);
            }
#if GameVersion_0_Release_2_0_209
            if (funcHandle == emtpyptr)
            {
                return(0);
            }

            uint func_address = ((uint)funcHandle.ToInt32()) + 0x20u;
            return(*(uint *)func_address);
#else
            return(0);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #11
0
        public unsafe static bool niecmod_script_set_custom_native_function_dlln_created(IntPtr internaldll_function, uint p_func_address)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(false);
            }
#if GameVersion_0_Release_2_0_209
            if (internaldll_function == emtpyptr)
            {
                return(false);
            }

            niec_native_func.OutputDebugString("set_custom_native_function_dlln_created() called");
            niec_native_func.OutputDebugString("internaldll_function adderss: 0x" + ((uint)(internaldll_function)).ToString("X"));

            uint func_address = 0;

            var dll       = (uint)internaldll_function + 0xC;
            var unknown_i = *(uint *)dll;

            if (unknown_i == 0)
            {
                niec_native_func.OutputDebugString("Failed");
                return(false);
            }
            else
            {
                niec_native_func.OutputDebugString("unknown_i adderss: 0x" + unknown_i.ToString("X"));

                func_address = unknown_i + 0xD4;

                niec_native_func.OutputDebugString("func_address adderss: 0x" + func_address.ToString("X"));

                *(uint *)func_address = (uint)p_func_address;

                niec_native_func.OutputDebugString("Done");
                return(true);
            }
#else
            return(false);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #12
0
        public unsafe static bool niecmod_script_set_custom_native_function(IntPtr funcHandle, IntPtr p_func_address)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(false);
            }
#if GameVersion_0_Release_2_0_209
            if (funcHandle == emtpyptr)
            {
                return(false);
            }

            uint func_address = ((uint)funcHandle.ToInt32()) + 0x20u;
            *(uint *)func_address = (uint)p_func_address.value;

            return(true);
#else
            return(false);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #13
0
        public unsafe static uint niecmod_safecall_script_get_func_ptr_dll(IntPtr internaldll_function)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(0);
            }
#if GameVersion_0_Release_2_0_209
            if (internaldll_function.value == null)
            {
                return(0);
            }

            uint func_address = 0;
            uint r            = 0;

            NFinalizeDeath.SafeCall(() =>
            {
                var ptr = (uint)internaldll_function.value;

                var dll    = ptr + 0x8u;
                var func_i = *(uint *)dll;

                if (func_i == 0)
                {
                    r = 0;
                    return;
                }
                else
                {
                    func_address = func_i + 0x18u;
                    r            = *(uint *)func_address;
                    return;
                }
            });
            return(r);
#else
            return(0);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #14
0
        public unsafe static uint niecmod_safecall_script_get_func_ptr_all(IntPtr internaldll_function, uint am, uint an)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(0);
            }

            if (internaldll_function.value == null)
            {
                return(0);
            }
            var p = niecmod_safecall_script_get_func_ptr(internaldll_function);

            if (p != 0 && p > an && p < am)
            {
                return(p);
            }
            else
            {
                return(niecmod_safecall_script_get_func_ptr_dll(internaldll_function));
            }
        }
Пример #15
0
        public static uint niecmod_safecall_script_get_func_ptr_all2(MethodInfo internal_function, uint am, uint an)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(0);
            }
#if GameVersion_0_Release_2_0_209
            if (internal_function == null)
            {
                return(0);
            }
            var p = niecmod_script_get_func_ptr2(internal_function);
            if (p != 0 && p > an && p < am)
            {
                return(p);
            }
            else
            {
                return(niecmod_safecall_script_get_func_ptr_dll2(internal_function));
            }
#else
            return(0);
#endif // GameVersion_0_Release_2_0_209
        }
Пример #16
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
        }
Пример #17
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
        }
Пример #18
0
        void StartUpSafeErrorTrapAdded()
        {
            if (NSC_ETRAP.IsDone)
            {
                return;
            }

            if (AssemblyCheckByNiec.IsInstalled("NRaasErrorTrap") || ShouldACoreScipt2020())
            {
                NiecTask.Perform(delegate
                {
                    if (!NFinalizeDeath.GameIs64Bit(true) && ShouldACoreScipt2020() && !NiecHelperSituation.isdgmods)
                    {
                        if (!NFinalizeDeath.DoneSafePreventGetAssembliesPro && NFinalizeDeath.func_address_GetAssemblies != 0)
                        {
                            NFinalizeDeath.RemovePreventGetAssemblies();
                        }

                        Type.GetType("NRaas.Common, NRaasErrorTrap").GetMethod("OnPreLoad", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Invoke(null, new object[0]);

                        var p = Type.GetType("NRaas.ErrorTrap, NRaasErrorTrap");
                        if (p == null)
                        {
                            NFinalizeDeath.Assert("Type.GetType(\"NRaas.ErrorTrap, NRaasErrorTrap\"); == null");
                            goto faled;
                        }
                        else
                        {
                            var m = p.GetMethod("OnScriptError", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                            if (m != null)
                            {
                                var myM = typeof(SCOSR).GetMethod("OnScriptError", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

                                dontcall = true;
                                OnScriptError(null, null);
                                dontcall = false;

                                // Required if no create method pointer.
                                Delegate.CreateDelegate(typeof(SCOSR._SafeScriptError), m);

                                if (!niec_script_func.niecmod_script_copy_ptr_func_to_func(myM, m, false, false, true, false))
                                {
                                    goto faled;
                                }
                            }
                            else
                            {
                                goto faled;
                            }
                        }
                        _SafeOnScriptError = null;
                        DoneSafeErrorTrap  = true;
                        ShouldInjectedMethodOnScriptError = true;
                        if (NiecHelperSituation.___bOpenDGSIsInstalled_)
                        {
                            SetBoolScriptCore2020(false, false, false);
                        }
                        else
                        {
                            SetBoolScriptCore2020(AssemblyCheckByNiec.IsInstalled("AweCore"), true, true);
                        }
                        return;
                    }
                    faled:
                    for (int i = 0; i < 100; i++)
                    {
                        Simulator.Sleep(0);
                    }
                    if (!DoneSafeErrorTrap && AssemblyCheckByNiec.IsInstalled("NRaasErrorTrap"))
                    {
                        Type.GetType("NRaas.Common, NRaasErrorTrap").GetMethod("OnPreLoad", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Invoke(null, new object[0]);
                    }
                    if (AssemblyCheckByNiec.IsInstalled("NRaasErrorTrap"))
                    {
                        Type type = Type.GetType("ScriptCore.ExceptionTrap, ScriptCore", true);
                        if (type != null)
                        {
                            FieldInfo mField = type.GetField("OnScriptError", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
                            if (mField != null)
                            {
                                MethodInfo mf = (mField.GetValue(null) as MulticastDelegate).method_info;
                                if (mf != null)
                                {
                                    NFinalizeDeath.sIs_m_OnScriptError = typeof(SCOSR).GetMethod("OnScriptError");
                                    if (mf == typeof(SCOSR).GetMethod("OnScriptError") || mf.DeclaringType == typeof(SCOSR))
                                    {
                                        DoneSafeErrorTrap = true;
                                    }
                                    else
                                    {
                                        SCOSR._SafeOnScriptError = (SCOSR._SafeScriptError)Delegate.CreateDelegate(typeof(SCOSR._SafeScriptError), mf);
                                        type = Type.GetType("ScriptCore.ExceptionTrap+ScriptError, ScriptCore", true);
                                        if (type != null)
                                        {
                                            mf = typeof(SCOSR).GetMethod("OnScriptError");
                                            if (mf != null)
                                            {
                                                mField.SetValue(null, Delegate.CreateDelegate(type, mf));
                                                DoneSafeErrorTrap = true;
                                                if (NiecHelperSituation.___bOpenDGSIsInstalled_)
                                                {
                                                    SetBoolScriptCore2020(false, false, false);
                                                }
                                                else
                                                {
                                                    SetBoolScriptCore2020(AssemblyCheckByNiec.IsInstalled("AweCore"), true, mField.GetValue(null) != null);
                                                }
                                                if (mField.GetValue(null) == null)
                                                {
                                                    NiecException.WriteLog("StartUpSafeErrorTrapAdded() Found mField.GetValue(null) == null");
                                                }
                                            }
                                            else
                                            {
                                                throw new NotSupportedException("OnScriptError not find");
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    NiecException.WriteLog("if (mf == null)");
                                }
                            }
                            else
                            {
                                throw new NotSupportedException("OnScriptError not find");
                            }
                        }
                    }
                });
            }
        }
Пример #19
0
        public unsafe static void init_class()
        {
            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 (done_init_class)
            {
                return;
            }

            done_init_class = true;

            var type = typeof(niec_native_func);
            var m01  = (MonoMethod)type.GetMethod("niecmod_native_load_library", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);

            //uint* at = (uint*)0;
            uint func_address = 0;
            int  tem          = 0;

            if (m01 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_load_library\") failed");
                done_init_class = false;
                goto skip2;
            }

            //at = (uint*)((int)m01.mhandle.obj_address());
            tem = native00.Length + native00.Length
                  - 0x32;

            var native00_address = (uint)native00.obj_address();
            func_address = native00_address + 0x14;


            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native00_address + i) = 0xCCCCCCCC;
            }

            native00.obj_address(); // check SIGSEGV

            *(uint *)(func_address)        = NFinalizeDeath.SwapOrgerBit32(0x908B5C24u);
            *(uint *)(func_address + 0x4)  = NFinalizeDeath.SwapOrgerBit32(0x0483C308u);
            *(uint *)(func_address + 0x8)  = NFinalizeDeath.SwapOrgerBit32(0x53FF1580u);
            *(uint *)(func_address + 0xC)  = NFinalizeDeath.SwapOrgerBit32(0x62F90090u);
            *(uint *)(func_address + 0x10) = NFinalizeDeath.SwapOrgerBit32(0xC3909090u);

            cache_done_niecmod_native_load_library =
                niec_script_func.niecmod_script_set_custom_native_function(m01.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////////////////////////////

skip2:
            var m02 = (MonoMethod)type.GetMethod("niecmod_native_debug_text_to_debugger", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m02 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_debug_text_to_debugger\") failed");
                done_init_class = false;
                goto skip3;
            }

            //at = (uint*)((int)m02.mhandle.obj_address());
            tem = native01.Length + native01.Length
                  - 0x32;

            var native01_address = (uint)native01.obj_address();
            func_address = native01_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native01_address + i) = 0xCCCCCCCC;
            }

            native01.obj_address(); // check SIGSEGV

            *(uint *)(func_address)        = NFinalizeDeath.SwapOrgerBit32(0x608B4C24u);
            *(uint *)(func_address + 0x4)  = NFinalizeDeath.SwapOrgerBit32(0x2483C108u);
            *(uint *)(func_address + 0x8)  = NFinalizeDeath.SwapOrgerBit32(0x51FF1514u);
            *(uint *)(func_address + 0xC)  = NFinalizeDeath.SwapOrgerBit32(0x63F90061u);
            *(uint *)(func_address + 0x10) = NFinalizeDeath.SwapOrgerBit32(0xC3909090u);

            cache_done_niecmod_native_debug_text_to_debugger =
                niec_script_func.niecmod_script_set_custom_native_function(m02.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////////////////////////////

skip3:
            var m03 = (MonoMethod)type.GetMethod("IsDebuggerAttached_internal", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m03 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"IsDebuggerAttached_internal\") failed");
                goto skip4;
            }

            tem = native02.Length + native02.Length
                  - 0x32;

            var native02_address = (uint)native02.obj_address();
            func_address = native02_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native02_address + i) = 0xCCCCCCCC;
            }

            native02.obj_address(); // check SIGSEGV

            *(uint *)(func_address)       = NFinalizeDeath.SwapOrgerBit32(0x64A13000u);
            *(uint *)(func_address + 0x4) = NFinalizeDeath.SwapOrgerBit32(0x00000FB6u);
            *(uint *)(func_address + 0x8) = NFinalizeDeath.SwapOrgerBit32(0x4002C390u);

            cache_done_IsDebuggerAttached_internal =
                niec_script_func.niecmod_script_set_custom_native_function(m03.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip4:
            var m04 = (MonoMethod)type.GetMethod("DebuggerBreak", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m04 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"DebuggerBreak\") failed");
                goto skip5;
            }

            tem = native03.Length + native03.Length
                  - 0x32;

            var native03_address = (uint)native03.obj_address();
            func_address = native03_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native03_address + i) = 0xCCCCCCCC;
            }

            native03.obj_address(); // check SIGSEGV

            *(uint *)(func_address) = NFinalizeDeath.SwapOrgerBit32(0xCCC3CCCCu);

            cache_done_IsDebuggerBreak_internal =
                niec_script_func.niecmod_script_set_custom_native_function(m04.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip5:
            var m05 = (MonoMethod)type.GetMethod("niecmod_native_ptr_fs_zero", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m05 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_ptr_fs_zero\") failed");
                goto skip6;
            }

            tem = native04.Length + native04.Length
                  - 0x32;

            var native04_address = (uint)native04.obj_address();
            func_address = native04_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native04_address + i) = 0xCCCCCCCC;
            }

            native04.obj_address(); // check SIGSEGV

            *(uint *)(func_address)       = NFinalizeDeath.SwapOrgerBit32(0x8B5C2404u);
            *(uint *)(func_address + 0x4) = NFinalizeDeath.SwapOrgerBit32(0x648B0331u);
            *(uint *)(func_address + 0x8) = NFinalizeDeath.SwapOrgerBit32(0xDBC3CCCCu);

            cache_done_niecmod_native_ptr_fs_zero =
                niec_script_func.niecmod_script_set_custom_native_function(m05.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip6:
            var m06 = (MonoMethod)type.GetMethod("niecmod_native_message_box", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m06 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_message_box\") failed");
                goto skip7;
            }

            tem = native05.Length + native05.Length
                  - 0x32;

            var native05_address = (uint)native05.obj_address();
            func_address = native05_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native05_address + i) = 0xCCCCCCCC;
            }

            native05.obj_address(); // check SIGSEGV

            byte[] nativefunc_messagebox =
            {
                0x8B, 0x5C, 0x24, 0x08, 0x83, 0xC3, 0x08, 0x89, 0x5C, 0x24, 0x08, 0x8B,
                0x5C, 0x24, 0x0C, 0x83, 0xC3, 0x08, 0x89, 0x5C, 0x24, 0x0C, 0x83, 0xEC,
                0x08, 0x8B, 0x5C, 0x24, 0x08, 0x89, 0x5C, 0x24, 0x04, 0xFF, 0x74, 0x24,
                0x18, 0xFF, 0x74, 0x24, 0x18, 0xFF, 0x74, 0x24, 0x18, 0xFF, 0x74, 0x24,
                0x18, 0xFF, 0x15, 0x00, 0x68, 0xF9, 0x00, 0x83, 0xC4, 0x08, 0xC3, 0xCC
            };

            for (int i = 0; i < nativefunc_messagebox.Length; i++)
            {
                *(byte *)(func_address + i) = nativefunc_messagebox[i];
            }

            cache_done_niecmod_native_message_box =
                niec_script_func.niecmod_script_set_custom_native_function(m06.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip7:
            var m07 = (MonoMethod)type.GetMethod("niecmod_native_cpuid", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m07 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_cpuid\") failed");
                goto skip8;
            }

            tem = native06.Length + native06.Length
                  - 0x32;

            var native06_address = (uint)native06.obj_address();
            func_address = native06_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native06_address + i) = 0xCCCCCCCC;
            }

            native06.obj_address(); // check SIGSEGV

            byte[] nativefunc_cpuid =
            {
                0x60, 0x8B, 0x44, 0x24, 0x24, 0x8B, 0x5C, 0x24, 0x28, 0x8B, 0x4C, 0x24,
                0x2C, 0x8B, 0x54, 0x24, 0x30, 0x8B, 0x00, 0x8B, 0x1B, 0x8B, 0x09, 0x8B,
                0x12, 0x0F, 0xA2, 0x55, 0x89, 0xE5, 0x83, 0xEC, 0x10, 0x89, 0x04, 0x24,
                0x89, 0x5C, 0x24, 0x04, 0x89, 0x4C, 0x24, 0x08, 0x89, 0x54, 0x24, 0x0C,
                0x8B, 0x44, 0x24, 0x38, 0x8B, 0x5C, 0x24, 0x3C, 0x8B, 0x4C, 0x24, 0x40,
                0x8B, 0x54, 0x24, 0x44, 0x8B, 0x3C, 0x24, 0x89, 0x38, 0x8B, 0x7C, 0x24,
                0x04, 0x89, 0x3B, 0x8B, 0x7C, 0x24, 0x08, 0x89, 0x39, 0x8B, 0x7C, 0x24,
                0x0C, 0x89, 0x3A, 0x83, 0xC4, 0x10, 0x5D, 0x61, 0xC3
            };

            for (int i = 0; i < nativefunc_cpuid.Length; i++)
            {
                *(byte *)(func_address + i) = nativefunc_cpuid[i];
            }

            cache_done_niecmod_native_cpuid =
                niec_script_func.niecmod_script_set_custom_native_function(m07.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip8:
            var m08 = (MonoMethod)type.GetMethod("niecmod_native_file_create", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m08 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_file_create\") failed");
                goto skip9;
            }

            tem = native07.Length + native07.Length
                  - 0x32;

            var native07_address = (uint)native07.obj_address();
            func_address = native07_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native07_address + i) = 0xCCCCCCCC;
            }

            native07.obj_address(); // check SIGSEGV

            byte[] createfile_func =
            {
                0x8B, 0x5C, 0x24, 0x04, 0x83, 0xC3, 0x08, 0x90, 0x90, 0x90, 0x90, 0x90,
                0x90, 0x90, 0x31, 0xC0, 0x50, 0x68, 0x00, 0x00, 0x00, 0x80, 0x6A, 0x02,
                0x50, 0x6A, 0x03, 0x68, 0x00, 0x00, 0x00, 0x40, 0x53, 0x90, 0x90, 0x90,
                0x90, 0xFF, 0x15, 0x54, 0x63, 0xF9, 0x00, 0x31, 0xDB, 0xC3, 0x90, 0x90,
                0x90, 0x90, 0x90, 0x90
            };

            for (int i = 0; i < createfile_func.Length; i++)
            {
                *(byte *)(func_address + i) = createfile_func[i];
            }

            cache_done_niecmod_native_file_create =
                niec_script_func.niecmod_script_set_custom_native_function(m08.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip9:
            var m09 = (MonoMethod)type.GetMethod("niecmod_native_file_writetext", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m09 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_file_writetext\") failed");
                goto skip10;
            }

            tem = native08.Length + native08.Length
                  - 0x32;

            var native08_address = (uint)native08.obj_address();
            func_address = native08_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native08_address + i) = 0xCCCCCCCC;
            }

            native08.obj_address(); // check SIGSEGV

            byte[] writetext_func =
            {
                0x8B, 0x44, 0x24, 0x08, 0x83, 0xC0, 0x08, 0x8B, 0x5C, 0x24, 0x08, 0x83,
                0xC3, 0x04, 0x8B, 0x1B, 0x01, 0xDB, 0x90, 0x90, 0x90, 0x31, 0xD2, 0x52,
                0x52, 0x53, 0x50, 0xFF, 0x74, 0x24, 0x14, 0xFF, 0x15, 0x94, 0x63, 0xF9,
                0x00, 0xC3
            };

            for (int i = 0; i < writetext_func.Length; i++)
            {
                *(byte *)(func_address + i) = writetext_func[i];
            }

            cache_done_niecmod_native_file_writetext =
                niec_script_func.niecmod_script_set_custom_native_function(m09.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip10:
            var m10 = (MonoMethod)type.GetMethod("niecmod_native_file_write", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m10 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_file_write\") failed");
                goto skip11;
            }

            tem = native09.Length + native09.Length
                  - 0x32;

            var native09_address = (uint)native09.obj_address();
            func_address = native09_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native09_address + i) = 0xCCCCCCCC;
            }

            native09.obj_address(); // check SIGSEGV

            byte[] write_func =
            {
                0x31, 0xDB, 0x53, 0x53, 0xFF, 0x74, 0x24, 0x14, 0xFF, 0x74, 0x24, 0x14,
                0xFF, 0x74, 0x24, 0x14, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90,
                0x90, 0x90, 0x90, 0x90, 0x90, 0xFF, 0x15, 0x94, 0x63, 0xF9, 0x00, 0xC3
            };

            for (int i = 0; i < write_func.Length; i++)
            {
                *(byte *)(func_address + i) = write_func[i];
            }

            cache_done_niecmod_native_file_write =
                niec_script_func.niecmod_script_set_custom_native_function(m10.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

skip11:
            var m11 = (MonoMethod)type.GetMethod("niecmod_native_file_close", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            if (m11 == null)
            {
                NFinalizeDeath.Assert("type.GetMethod(\"niecmod_native_file_close\") failed");
                throw new NotSupportedException();
            }

            tem = native10.Length + native10.Length
                  - 0x32;

            var native10_address = (uint)native10.obj_address();
            func_address = native10_address + 0x14;

            for (int i = 0x10; i < tem; i++)
            {
                *(uint *)(native10_address + i) = 0xCCCCCCCC;
            }

            native10.obj_address(); // check SIGSEGV

            byte[] fileclose_func =
            {
                0xFF, 0x74, 0x24, 0x04, 0x90, 0xFF, 0x15, 0x9C, 0x63, 0xF9, 0x00, 0xC3
            };

            for (int i = 0; i < fileclose_func.Length; i++)
            {
                *(byte *)(func_address + i) = fileclose_func[i];
            }

            cache_done_niecmod_native_file_close =
                niec_script_func.niecmod_script_set_custom_native_function(m11.mhandle, new IntPtr()
            {
                value = (void *)func_address
            });

            ////////////////////////////////////////////////////////////////////////////////

            if (m01 != null)
            {
                OutputDebugString("niecmod_native_load_library: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m01.mhandle).ToString("X"));
            }
            if (m02 != null)
            {
                OutputDebugString("niecmod_native_debug_text_to_debugger: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m02.mhandle).ToString("X"));
            }
            if (m03 != null)
            {
                OutputDebugString("IsDebuggerAttached_internal: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m03.mhandle).ToString("X"));
            }
            if (m04 != null)
            {
                OutputDebugString("DebuggerBreak: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m04.mhandle).ToString("X"));
            }
            if (m05 != null)
            {
                OutputDebugString("niecmod_native_ptr_fs_zero: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m05.mhandle).ToString("X"));
            }
            if (m06 != null)
            {
                OutputDebugString("niecmod_native_message_box: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m06.mhandle).ToString("X"));
            }
            if (m07 != null)
            {
                OutputDebugString("niecmod_native_cpuid: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m07.mhandle).ToString("X"));
            }
            if (m08 != null)
            {
                OutputDebugString("niecmod_native_file_create: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m08.mhandle).ToString("X"));
            }
            if (m09 != null)
            {
                OutputDebugString("niecmod_native_file_writetext: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m09.mhandle).ToString("X"));
            }
            if (m10 != null)
            {
                OutputDebugString("niecmod_native_file_write: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m10.mhandle).ToString("X"));
            }
            if (m11 != null)
            {
                OutputDebugString("niecmod_native_file_close: func_address: 0x" + niec_script_func.niecmod_script_get_func_ptr(m11.mhandle).ToString("X"));
            }
#endif // GameVersion_0_Release_2_0_209
        }
Пример #20
0
        public unsafe static uint niecmod_script_get_custom_native_function_dll_created(IntPtr internaldll_function)
        {
            if (NFinalizeDeath.GameIs64Bit(false))
            {
                return(0);
            }
#if GameVersion_0_Release_2_0_209
            if (internaldll_function == emtpyptr)
            {
                return(0);
            }

            niec_native_func.OutputDebugString("get_custom_native_function_dll_created() called");
            niec_native_func.OutputDebugString("internaldll_function adderss: 0x" + ((uint)(internaldll_function)).ToString("X"));

            uint func_address = 0;

            var dll       = (uint)internaldll_function + 0xC;
            var unknown_i = *(uint *)dll;

            if (unknown_i == 0)
            {
                niec_native_func.OutputDebugString("Failed");
                return(0);
            }
            else
            {
                niec_native_func.OutputDebugString("unknown_i adderss: 0x" + unknown_i.ToString("X") + " unknown_i + 0x4Cu: 0x" + ((uint)(unknown_i + 0x4Cu)).ToString("X"));

                var unknown_a = unknown_i + 0x4Cu;
                niec_native_func.OutputDebugString("unknown_a adderss: 0x" + unknown_a.ToString("X"));

                if (unknown_a == 0 || unknown_a < 0x1000)
                {
                    niec_native_func.OutputDebugString("Failed");
                    return(0);
                }

                var unknown_b = *(uint *)unknown_a;
                niec_native_func.OutputDebugString("unknown_b adderss: 0x" + unknown_b.ToString("X") + " unknown_b + 0x14u: 0x" + ((uint)(unknown_b + 0x14u)).ToString("X"));

                if (unknown_b == 0 || unknown_b < 0x1000)
                {
                    niec_native_func.OutputDebugString("Failed");
                    return(0);
                }

                var unknown_bb = *(uint *)unknown_b + 0x14u;
                niec_native_func.OutputDebugString("unknown_bb adderss: 0x" + unknown_bb.ToString("X"));

                if (unknown_bb == 0 || unknown_bb < 0x1000 || unknown_bb == 0xFFFF0004)
                {
                    niec_native_func.OutputDebugString("Failed");
                    return(0);
                }



                func_address = unknown_bb + 0xC;
                niec_native_func.OutputDebugString("func_address adderss: 0x" + (*(uint *)func_address).ToString("X"));

                return(*(uint *)func_address);
            }
#else
            return(0);
#endif // GameVersion_0_Release_2_0_209
        }