Example #1
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
        }