SlimDx Rendering - Invalid call menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SlimDx Rendering - Invalid call

    So I'm trying to get rendering to work in my bot with SlimDx.

    Camera class:
    Code:
    public struct CameraInfo
        {
            uint unk0;
            uint unk1;
            public Vector3 Position;
            public Matrix3 Matrix;
            public float FieldOfView;
            float unk2;
            int unk3;
            public float NearZ;
            public float FarZ;
            public float Aspect;
        }
    
        public static unsafe class Camera
        {
            public static void Initialize()
            {
                _GetFov = Helper.Magic.RegisterDelegate<GetFovDelegate>(Helper.Magic.GetObjectVtableFunction(Pointer, 0));
                _Forward = Helper.Magic.RegisterDelegate<ForwardDelegate>(Helper.Magic.GetObjectVtableFunction(Pointer, 1));
                _Right = Helper.Magic.RegisterDelegate<RightDelegate>(Helper.Magic.GetObjectVtableFunction(Pointer, 2));
                _Up = Helper.Magic.RegisterDelegate<UpDelegate>(Helper.Magic.GetObjectVtableFunction(Pointer, 3));
            }
    
            private static IntPtr Pointer
            {
                get { return new IntPtr(Offsets.ActiveCamera); }
            }
    
            [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
            public delegate float GetFovDelegate(IntPtr ptr);
            private static GetFovDelegate _GetFov;
    
            [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
            public delegate Vector3* ForwardDelegate(IntPtr ptr, Vector3* vecOut);
            private static ForwardDelegate _Forward;
    
            [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
            public delegate Vector3* RightDelegate(IntPtr ptr, Vector3* vecOut);
            private static RightDelegate _Right;
    
            [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
            public delegate Vector3* UpDelegate(IntPtr ptr, Vector3* vecOut);
            private static UpDelegate _Up;
    
            public static float FieldOfView
            {
                get
                {
                    return _GetFov(Pointer);
                }
            }
    
            public static Vector3 Forward
            {
                get
                {
                    var res = new Vector3();
                    _Forward(Pointer, &res);
                    return res;
                }
            }
    
            public static Vector3 Right
            {
                get
                {
                    var res = new Vector3();
                    _Right(Pointer, &res);
                    return res;
                }
            }
    
            public static Vector3 Up
            {
                get
                {
                    var res = new Vector3();
                    _Up(Pointer, &res);
                    return res;
                }
            }
    
            public static Matrix Projection
            {
                get
                {
                    var cam = GetCamera();
                    return Matrix.PerspectiveFovRH(FieldOfView * 0.6f, cam.Aspect, cam.NearZ, cam.FarZ);
                }
            }
    
            public static Matrix View
            {
                get
                {
                    var cam = GetCamera();
                    var eye = cam.Position;
                    var at = eye + Camera.Forward;
                    return Matrix.LookAtRH(eye, at, new Vector3(0, 0, 1));
                }
            }
    
            public static CameraInfo GetCamera()
            {
                return Helper.Magic.ReadStruct<CameraInfo>(new IntPtr(Offsets.ActiveCamera));
            }
        }
    Rendering class:
    Code:
        [StructLayout(LayoutKind.Sequential)]
        public struct PositionColored
        {
            public static readonly VertexFormat FVF = VertexFormat.Position | VertexFormat.Diffuse;
            public static readonly int Stride = Vector3.SizeInBytes + sizeof(int);
    
            public Vector3 Position;
            public int Color;
    
            public PositionColored(Vector3 pos, int col)
            {
                Position = pos;
                Color = col;
            }
        }
    
        public static class Rendering
        {
            private static readonly List<IResource> _resources = new List<IResource>();
            private static IntPtr _usedDevicePointer = IntPtr.Zero;
    
            public static Device Device { get; private set; }
    
            public static void Initialize(IntPtr devicePointer)
            {
                if (_usedDevicePointer != devicePointer)
                {
                    Debug.WriteLine("Rendering: Device initialized on " + devicePointer);
                    Device = Device.FromPointer(devicePointer);
                    _usedDevicePointer = devicePointer;
                }
    
                Camera.Initialize();
            }
    
            public static void RegisterResource(IResource source)
            {
                _resources.Add(source);
            }
    
            private static void InternalRender(Location target, PositionColored[] vertices)
            {
                var camera = Camera.GetCamera();
    
                var eye = camera.Position;
                var lookat = camera.Position + Camera.Forward;
                var up = new Vector3(0, 0, 1);
    
                var matWorld = Matrix.Translation(target.ToVector3());
                var matView = Matrix.LookAtRH(eye, lookat, up);
                var matProj = Matrix.PerspectiveFovRH(camera.FieldOfView * 0.6f, 1.335f, camera.NearZ, camera.FarZ);
    
                Device.VertexShader = null;
                Device.PixelShader = null;
                Device.SetRenderState(RenderState.AlphaBlendEnable, true);
                Device.SetRenderState(RenderState.BlendOperation, BlendOperation.Add);
                Device.SetRenderState(RenderState.DestinationBlend, Blend.InverseSourceAlpha);
                Device.SetRenderState(RenderState.SourceBlend, Blend.SourceAlpha);
                Device.SetRenderState(RenderState.Lighting, 0);
                Device.SetTexture(0, null);
                Device.SetRenderState(RenderState.CullMode, Cull.None);
    
    
                Result res = Device.DrawUserPrimitives(PrimitiveType.LineList, (vertices.Length / 2), vertices);
            }
    
            private static PositionColored[] LineVertices(Location start, Location end, Color color)
            {
                var vertices = new PositionColored[2];
                vertices[0] = new PositionColored(new Vector3(0f, 0f, 0f), System.Drawing.Color.Yellow.ToArgb());
                vertices[1] = new PositionColored(new Vector3((start.X - end.X), (start.Y - end.Y), (start.Z - end.Z)), System.Drawing.Color.Yellow.ToArgb());
                return vertices;
            }
    
            public static void DrawLine(Location from, Location to, Color color)
            {
                InternalRender(from, LineVertices(to, from, color));
            }
    But when I call Rendering.DrawLine I get this error:
    Code:
    16:39:53] [Drawing] Error: SlimDX.Direct3D9.Direct3D9Exception: D3DERR_INVALIDCALL: Invalid call (-2005530516)
       at SlimDX.Result.Throw[T](Object dataKey, Object dataValue)
       at SlimDX.Result.Record[T](Int32 hr, Boolean failed, Object dataKey, Object dataValue)
       at SlimDX.Direct3D9.Device.DrawUserPrimitives[T](PrimitiveType primitiveType, Int32 startIndex, Int32 primitiveCount, T[] data)
       at SlimDX.Direct3D9.Device.DrawUserPrimitives[T](PrimitiveType primitiveType, Int32 primitiveCount, T[] data)
       at cleanCore.D3D.Rendering.InternalRender(Location target, PositionColored[] vertices) in C:\Users\Michael\Desktop\Projects\Developement\World of Warcraft\cleanCore\cleanCore\D3D\Rendering.cs:line 74
       at cleanCore.D3D.Rendering.DrawLine(Location from, Location to, Color color) in C:\Users\Michael\Desktop\Projects\Developement\World of Warcraft\cleanCore\cleanCore\D3D\Rendering.cs:line 87
       at cleanLayer.Scripting.Scripts.DrawingScript.OnTick() in C:\Users\Michael\Desktop\Projects\Developement\World of Warcraft\cleanCore\cleanLayer\Scripting\Scripts\DrawingScript.cs:line 38
       at cleanLayer.Scripting.ScriptThread.Tick() in C:\Users\Michael\Desktop\Projects\Developement\World of Warcraft\cleanCore\cleanLayer\Scripting\ScriptThread.cs:line 48
       at cleanLayer.Scripting.Script.Tick() in C:\Users\Michael\Desktop\Projects\Developement\World of Warcraft\cleanCore\cleanLayer\Scripting\Script.cs:line 99
    I talked to Thongs about this, and he sent me his code, and for him it's working just fine yet for me it's not. I'm however using this approach to get the device pointer (from caytchen's cleanCore):
    Code:
                var window = new Form();
                IntPtr direct3D = Direct3DAPI.Direct3DCreate9(Direct3DAPI.SDKVersion);
                if (direct3D == IntPtr.Zero)
                    throw new Exception("Direct3DCreate9 failed (SDK Version: " + Direct3DAPI.SDKVersion + ")");
                var pp = new Direct3DAPI.PresentParameters { Windowed = true, SwapEffect = 1, BackBufferFormat = 0 };
                var createDevice = Helper.Magic.RegisterDelegate<Direct3DAPI.Direct3D9CreateDevice>(Helper.Magic.GetObjectVtableFunction(direct3D, 16));
                IntPtr device;
                if (createDevice(direct3D, 0, 1, window.Handle, 0x20, ref pp, out device) < 0)
                    throw new Exception("Failed to create device");
    
                EndScenePointer = Helper.Magic.GetObjectVtableFunction(device, Direct3DAPI.EndSceneOffset);
                ResetPointer = Helper.Magic.GetObjectVtableFunction(device, Direct3DAPI.ResetOffset);
                ResetExPointer = Helper.Magic.GetObjectVtableFunction(device, Direct3DAPI.ResetExOffset);
    
                var deviceRelease = Helper.Magic.RegisterDelegate<Direct3DAPI.D3DRelease>(Helper.Magic.GetObjectVtableFunction(device, 2));
                var release = Helper.Magic.RegisterDelegate<Direct3DAPI.D3DRelease>(Helper.Magic.GetObjectVtableFunction(direct3D, 2));
    
                Rendering.Initialize(device);
    While he is just using an offset. Do any of you have any idea what might be causing this? I'm out of ideas.

    SlimDx Rendering - Invalid call
  2. #2
    Dysphorie's Avatar Member
    Reputation
    4
    Join Date
    Aug 2011
    Posts
    12
    Thanks G/R
    0/1
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try replacing your drawuserprimitive by this one

    Code:
    device.DrawUserPrimitives<LineVertex>(PrimitiveType.LineList, 0, vertices.Length / 2, vertices);

  3. #3
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I take it you mean PositionColored (instead of LineVertex) in my case. It made no difference:
    D3DERR_INVALIDCALL: Invalid call (-2005530516)
    Last edited by miceiken; 08-07-2011 at 02:00 PM.

  4. #4
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Run DX Debug runtimes with debug output on full and see what information it provides.

  5. #5
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did try this, but the amount of log levels made both DebugView and WoW not respond. Even with filters on. I'll give it another shot tho.

  6. #6
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You probably don't have to turn the log level all the way up. From my experience any kind of error will show up on the lower levels, while the higher ones also shows more detailed output.

  7. #7
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think you're using the wrong device. You set up your dummy device in that last snippet, then pass that to Rendering.Initialize(), which creates the SlimDX Device object by doing a 'Device.FromPointer(devicePointer)'. At that point, devicePointer is your dummy device, not WoW's device. At least that's my reading of your code.

  8. #8
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Doesn't creating a new device in a program where it already exists just return the current device? My EndScene hooks works just fine, but I'll take a look at it.

  9. #9
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't believe so. The vtable is the same, so when you hook EndScene you're hooking it for all devices (remember it is just a static function with a 'hidden' this parameter). You can have multiple devices in a single application though. The idea of creating a dummy device is to use it simply to get the location of the vtable, and create your EndScene hook (or whatever other hook you want). Once you've done that, you wait for your hook function to be called. The device pointer passed as 'this' is the pointer to the device that WoW is using. Create your device object from that, and then you can draw using that device in your EndScene hook.

  10. #10
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woot! It works.
    What I did was that I initialized the rendering on the first EndScene detour-call, because it passes the pointer to the device as a parameter.

    ---------- Post added at 10:05 AM ---------- Previous post was at 09:28 AM ----------

    A few issues appeared tho. If I draw a line it works just fine, but if I draw both a line and a circle, the line goes the opposite direction. I think this is because I set 2 different targets in the same frame? The drawings also depends on camera placing. Whenever I look straight at the target with camera behind my back it appears on the unit, but if I move the camera and set it sideways, the circle doesn't stay on the unit. (Is this because of the Camera.Forward thing?)

    SlimDx Rendering - Invalid call-rxdgk-jpg

    Link to picture: https://i.imgur.com/RXdgK.jpg
    Last edited by miceiken; 08-08-2011 at 09:07 AM.

  11. #11
    adaephon's Avatar Active Member
    Reputation
    76
    Join Date
    May 2009
    Posts
    167
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep exactly . Probably make sure you release the dummy one you created. Interestingly, I was trying to do a quick repro, and my hook would never run when I had the debug runtime enabled, so maybe there's something funky in that method of hooking + debug runtime - maybe that was the issue you experienced rather than excessive logging volume. Not sure what issue is, and not looking into it too much - my hook works fine with debug runtime.

  12. #12
    Thongs's Avatar Member
    Reputation
    10
    Join Date
    Oct 2006
    Posts
    51
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by miceiken View Post
    Woot! It works.
    What I did was that I initialized the rendering on the first EndScene detour-call, because it passes the pointer to the device as a parameter.

    ---------- Post added at 10:05 AM ---------- Previous post was at 09:28 AM ----------

    A few issues appeared tho. If I draw a line it works just fine, but if I draw both a line and a circle, the line goes the opposite direction. I think this is because I set 2 different targets in the same frame? The drawings also depends on camera placing. Whenever I look straight at the target with camera behind my back it appears on the unit, but if I move the camera and set it sideways, the circle doesn't stay on the unit. (Is this because of the Camera.Forward thing?)

    SlimDx Rendering - Invalid call-rxdgk-jpg

    Link to picture: https://i.imgur.com/RXdgK.jpg
    I ran into this problem as well, where facing directly at a unit it would be correct, but if the unit is on the side of my screen, it's slightly off. After some tinkering, I fixed it with playing with the second value set in my projection matrix.

    Code:
    Matrix matProj = Matrix.PerspectiveFovRH(cam.FieldOfView * 0.6f, (float)(1.335), cam.NearPlane, cam.FarPlane);
    Device.SetTransform(TransformState.Projection, matProj);
    As you can see, I found that 1.335f worked perfectly for me.

  13. #13
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1.335f is what I used as well, so I suppose it doesn't work that great. I am supposed to get the aspect from the camera struct I think but last time I debugged it it was 0.0f

  14. #14
    suicidity's Avatar Contributor
    Reputation
    207
    Join Date
    Oct 2006
    Posts
    1,439
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Calculate the Aspect ratio yourself, it's not hard.


  15. #15
    miceiken's Avatar Contributor Authenticator enabled
    Reputation
    209
    Join Date
    Dec 2007
    Posts
    401
    Thanks G/R
    7/9
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I read up on it now, I should be using 1.78f, and that works. Next will be to find the height and width of the wow window.


    Thanks for your help, fixed the line issue as well

Page 1 of 2 12 LastLast

Similar Threads

  1. Rendering with SlimDX
    By Thongs in forum WoW Memory Editing
    Replies: 11
    Last Post: 08-01-2011, 04:07 PM
  2. Where to get a render?
    By lohkies in forum Art & Graphic Design
    Replies: 2
    Last Post: 03-06-2007, 04:25 PM
  3. Call of duty 2 crack cd key.
    By Goggelpuff in forum Gaming Chat
    Replies: 3
    Last Post: 11-01-2006, 09:18 AM
  4. How do I render Vid's in fraps?
    By theillbehaviored in forum World of Warcraft General
    Replies: 0
    Last Post: 09-25-2006, 09:54 AM
  5. How To Get to Que'thelas or w/e its called!!!
    By Tbone in forum World of Warcraft Exploits
    Replies: 17
    Last Post: 07-25-2006, 10:28 AM
All times are GMT -5. The time now is 10:13 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search