Example #1
0
 internal void SetHandle(NativeHandle nativeHandle)
 {
     if (this.nativeHandle != null)
     {
         throw new InvalidOperationException("Native object is already associated with a native handle");
     }
     this.nativeHandle = nativeHandle;
     Initialize();
 }
Example #2
0
 public static bool TryDereference(IntPtr address, out NativeHandle handle)
 {
     if (address == IntPtr.Zero)
     {
         handle = default;
         return(false);
     }
     if (!nativeDictionary.TryGetValue(address, out handle))
     {
         handle = new NativeHandle(address);
     }
     return(true);
 }
Example #3
0
        static unsafe partial void SetNativeHooks()
        {
            InitRectangleHooks();
            InitGPTHooks();

            Hook.Create <ThisCall0>(AddressOfFunction(FunctionNames.BWLD_Render), ctx =>
            {
                return((ecx) =>
                {
                    var bwld = NativeObject.FromPointer <BWLD>(ecx);
                    ctx.CallOriginal(o => o(ecx));
                    bwld.RenderOne();
                    return new IntPtr(1);
                });
            }).Initialize();

            Hook.Create <StdCall1>(AddressOfFunction(FunctionNames.Malloc), ctx =>
            {
                return((size) =>
                {
                    return NativeHandle.Alloc((int)size).Address;
                });
            }).Initialize();

            Hook.Create <StdCall1>(AddressOfFunction(FunctionNames.Free), ctx =>
            {
                return((address) =>
                {
                    NativeHandle.Free(address);
                    return new IntPtr(1);
                });
            }).Initialize();

            Hook.Create <StdCall0>(AddressOfFunction(FunctionNames.__WinMainCRTStartup), ctx =>
            {
                return(() =>
                {
                    GameTimer = new GameTimer();
                    var envStrings = PInvoke.Call(LibraryNames.KERNEL32, "GetEnvironmentStrings");
                    Marshal.WriteIntPtr((IntPtr)0x004EA1A4, envStrings);
                    UnmanagedFunctionCall.StdCall(AddressOfFunction(FunctionNames.__cinit));
                    UnmanagedFunctionCall.StdCall(AddressOfFunction(FunctionNames.WinMain), ModuleHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                    return IntPtr.Zero;
                });
            }).Initialize();
        }