Exemplo n.º 1
0
        // For the case where we already have a native IDirect3D9 object and we want to override some of it's functions.
        public IDirect3D9(D3D9.IDirect3D9* InNativeIDirect3D9)
        {
            NativeIDirect3D9 = InNativeIDirect3D9;

            // Override the functions in NativeIDirect3D9 with our own.
            OverrideFunctions();
        }
Exemplo n.º 2
0
        // For the case where we don't have a native IDirect3D object so we want one created for us.
        public IDirect3D9(ushort SdkVersion)
        {
            // Create the real IDirect3D9 object.
            NativeIDirect3D9 = D3D9.Direct3DCreate9(SdkVersion);

            // Override the functions in NativeIDirect3D9 with our own.
            OverrideFunctions();
        }
Exemplo n.º 3
0
        public uint CreateDevice(D3D9.IDirect3D9* This, uint adapter, uint deviceType, IntPtr focusWindow,
            uint behaviorFlags, IntPtr presentationParameters,
            D3D9.IDirect3DDevice9* deviceInterface)
        {
            LuaInterface.LoggingInterface.Log("CreateDevice Start...");
            RealCreateDevice =
                (DelegateCreateDevice)
                Marshal.GetDelegateForFunctionPointer(OriginalVFTable[16], typeof (DelegateCreateDevice));

            //Call the function to create the device.  The pointer to the device is stored in deviceInterface
            // The result code is saved to CreateDevice (0 means Good)
            LuaInterface.LoggingInterface.Log("RealCreateDevice Start...");
            uint CreateDevice = RealCreateDevice(This, adapter, deviceType, focusWindow, behaviorFlags,
                                                 presentationParameters, deviceInterface);

            // if creation was successful, then remap appopriate function pointers for EndScene
            if (CreateDevice == 0)
            {
                LuaInterface.LoggingInterface.Log(String.Format("CreateDevice = {0}", CreateDevice));
                var device = new IDirect3DDevice9(This, deviceInterface);
            }

            LuaInterface.LoggingInterface.Log("Returning CreateDevice");
            return CreateDevice;
        }
Exemplo n.º 4
0
        public uint EndScene(D3D9.IDirect3DDevice9 Device)
        {
            lock (LuaInterface.dataLock)
            {
                //Kernel32.SuspendThread(LuaInterface.WowMainThreadId);

                if (EndSceneDebug)
                    LuaInterface.LoggingInterface.LogEndScene(true);

                try
                {

                    switch (LuaInterface.LuaState)
                    {
                        case 255:
                            // NOTE: disabled logging of each EndScene message as it was driving me mad during debug ;)
                            //LuaInterface.LoggingInterface.Log("EndScene()");
                            break;

                        case 0: // Need registration
                            LuaInterface.LoggingInterface.Log("EndScene() - Lua registering ...");
                            LuaInterface.Patch();
                            if (!LuaInterface.InputHandlerRegistered)
                            {
                                LuaInterface.RegisterLuaInputHandler();
                                LuaInterface.InputHandlerRegistered = true;
                            }
                            LuaInterface.LoggingInterface.Log("EndScene() - Lua registered");

                            // Always last
                            LuaInterface.LuaState = 255;
                            break;

                        case 1:
                            //check for pending do_string's
                            LuaInterface.LoggingInterface.Log("EndScene() - DoString Starting ...");

                            //LuaInterface.DoString(LuaInterface.PendingDoString);
                            LuaInterface.DoString(LuaInterface.PendingDoString);
                            LuaInterface.LoggingInterface.Log("EndScene() - LuaDoString Done");

                            // Always last
                            LuaInterface.LuaState = 255;
                            break;

                        case 2:
                            //check for pending do_string's with registered callback
                            LuaInterface.LoggingInterface.Log(
                                string.Format("EndScene() - DoStringEx Starting ...",
                                              LuaInterface.PendingDoString));

                            //LuaInterface.DoString(LuaInterface.PendingDoString);
                            LuaInterface.DoStringEx(LuaInterface.PendingDoString);
                            LuaInterface.LoggingInterface.Log("EndScene() - DoStringEx done");

                            // Always last
                            LuaInterface.LuaState = 255;
                            break;

                        case 3: // Unregister handle
                            LuaInterface.LoggingInterface.Log("EndScene() - Lua un-registering ...");
                            LuaInterface.RestorePatch();
                            LuaInterface.LoggingInterface.Log("EndScene() - Lua un-registered");

                            // Always last
                            LuaInterface.LuaState = 255;
                            break;

                        default: // Unknown state throw exception
                            throw new Exception("Unknown EndScene State: " + LuaInterface.LuaState);

                    }

                    if (EndSceneDebug)
                    {
                        LuaInterface.LoggingInterface.Log(string.Format("{0:X} Device", (uint)&Device));
                        LuaInterface.LoggingInterface.Log(string.Format("{0:X} EndScene()", (uint)OriginalEndScene));
                    }

                }
                catch (Exception e)
                {
                    LuaInterface.LoggingInterface.Log(string.Format("EndScene() - Exception: {0}",
                                                                    e.ToString()));
                    LuaInterface.LuaState = 255;
                }
                // NativeIDirect3DDevice9->VFTable[0][42] = Marshal.GetFunctionPointerForDelegate(MyEndScene);

                // LuaInterface.LoggingInterface.Log("EndScene " + LuaInterface.LuaState + " done");

                if (EndSceneDebug)
                    LuaInterface.LoggingInterface.LogEndScene(false);

                //LuaInterface.LoggingInterface.Log(string.Format("Device:{0} RealEndScene:{1}", Device, RealEndScene));
                //Kernel32.ResumeThread(LuaInterface.WowMainThreadId);

                return RealEndScene(Device);
            }
        }
Exemplo n.º 5
0
        public IDirect3DDevice9(D3D9.IDirect3D9* InNativeIDirect3D9, D3D9.IDirect3DDevice9* InNativeIDirect3DDevice9)
        {
            NativeIDirect3D9 = InNativeIDirect3D9;
            NativeIDirect3DDevice9 = InNativeIDirect3DDevice9;

            // Override the functions in NativeIDirect3DDevice9 with our own.
            OverrideFunctions();
        }