Designing in-process classes for objects menu

User Tag List

Results 1 to 9 of 9
  1. #1
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Designing in-process classes for objects

    Since I've started to move in-process with my C#, the classes seem to be annoying to type out. This question goes out mostly to Apoc and jjaa, but is there anyway to avoid typing all the crap, like the type of every value in the class so you can use a pointer? For example:

    Code:
    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi, Pack = 4)]
        public unsafe struct MovementFields
        {
            [FieldOffset(0x0), MarshalAs(UnmanagedType.ByValArray, 
                SizeConst = 4, ArraySubType = UnmanagedType.U4)]
            public fixed uint unk1[4];
            [FieldOffset(0x10), MarshalAs(UnmanagedType.R4)]
            public float X;                                             //0x10-0x14
            [FieldOffset(0x14), MarshalAs(UnmanagedType.R4)]
            public float Y;
            [FieldOffset(0x18), MarshalAs(UnmanagedType.R4)]
            public float Z;
            [FieldOffset(0x1C), MarshalAs(UnmanagedType.R4)]
            public float rot;                                           //0x1C-0x20
            [FieldOffset(0x20), MarshalAs(UnmanagedType.ByValArray, 
                SizeConst = 4, ArraySubType = UnmanagedType.U4)]
            public fixed uint unk2[9];
            [FieldOffset(0x44), MarshalAs(UnmanagedType.U4)]
            public uint movementflag;
            [FieldOffset(0x48), MarshalAs(UnmanagedType.U4)]
            public uint playerstate;
            [FieldOffset(0xBC), MarshalAs(UnmanagedType.U4)]
            public uint unkBC;
        }
    That took forever to type. Any way to avoid typing all of that? Even just a little bit, because I have a LOT more classes to do like this...

    Designing in-process classes for objects
  2. #2
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know an easier way to define ingame classes.... Use C++!

    Sorry, couldn't help myself.

  3. #3
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lol. I'm already importing enough functions >.> C# is just more comfortable... Except for the ridiculous class/struct ptr definitions...

  4. #4
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, another question for Apoc :P. Is there a way to register a C# callback from C++? I have a native dll with a bunch of functions. Is there a way to register an event from the native dll so that when a condition occurs, your C# gets executed? I'm hooking SendPacket and Recvpacket and I need a way to do this.

  5. #5
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just lay out the struct the same as you normally would, just use a different setup.

    Code:
            [StructLayout(LayoutKind.Sequential)]
            public struct MovementFields
            {
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] 
                public uint[] unk1;
                public float X;                                             //0x10-0x14
                public float Y;
                public float Z;
                public float rot;                                           //0x1C-0x20
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] 
                public uint[] unk2;
                public uint movementflag;
                public uint playerstate;
                public uint unkBC;
            }
    You only need to set attribs for arrays, and some other *very* specific exceptions. 99% of the time however, you won't need to set the actual type, as the marshaler can figure them out.

    Also note; when using SizeConst on arrays, it defines the LENGTH of the ARRAY. Not the size of the datatype. So you need to fix that to match properly. (No, .NET currently has no support for variable length arrays. I wish it did. )

    You can even clean the above up using some struct nesting.

    Code:
            [StructLayout(LayoutKind.Sequential)]
            public struct MovementFields
            {
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] 
                public uint[] unk1;
                public WOWPOS pos;                                             //0x10-0x14
                public float rot;                                           //0x1C-0x20
                [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] 
                public uint[] unk2;
                public uint movementflag;
                public uint playerstate;
                public uint unkBC;
            }
    
            [StructLayout(LayoutKind.Sequential)]
            public struct WOWPOS
            {
                public float X;
                public float Y;
                public float Z;
            }
    As for the callback;

    Create a delegate to handle the callback.

    Example;

    Code:
    private delegate void CallbackHandler();
    
    private CallbackHandler _handler = Handler;
    
    private void Handler()
    {
    // Do shit here
    }
    
    public void CreateCallback()
    {
    IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(_handler);
    // Do whatever you need to setup the callback. (PInvoke, etc.)
    // callbackPtr is the pointer you need to pass.
    }
    We do this with EnumVisibleObjects, and a few other things. Works fine.

    You *may* need to add the [UnmanagedFunctionPointer(CallingConvention.xxx)] attribute to the delegate. So you may want to test that first.

  6. #6
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a ton Apoc!

  7. #7
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the delegate callback, the native code can just call the managed code? As in asm, it will be: Call 0xDEADBEEF? I thought it would have to be some sort of event handling.
    Last edited by lanman92; 07-07-2009 at 06:22 PM.

  8. #8
    Apoc's Avatar Angry Penguin
    Reputation
    1387
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/12
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lanman92 View Post
    For the delegate callback, the native code can just call the managed code? As in asm, it will be: Call 0xDEADBEEF? I thought it would have to be some sort of event handling.
    Assuming your C++ method takes a pointer to the function as the callback, it'll work perfectly fine.

  9. #9
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow. The CLR is an amazing thing...

Similar Threads

  1. looking for Dk custom class, for ppather
    By Dropsick in forum WoW Bot Maps And Profiles
    Replies: 5
    Last Post: 12-05-2008, 09:51 PM
  2. Updated Custom Classes for PPather + Bonus BG Botting.
    By Come Undone in forum World of Warcraft Bots and Programs
    Replies: 5
    Last Post: 08-18-2008, 09:59 AM
  3. Custom classes for Glider Elite
    By azzi88 in forum World of Warcraft Bots and Programs
    Replies: 13
    Last Post: 06-04-2008, 03:12 PM
  4. reskins for all classes for both male and female
    By Corroasive in forum WoW ME Questions and Requests
    Replies: 0
    Last Post: 05-17-2008, 11:08 AM
  5. [Request] Shaman Custom class for Mmoglider
    By lohkies in forum World of Warcraft General
    Replies: 5
    Last Post: 02-05-2008, 01:31 AM
All times are GMT -5. The time now is 08:58 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search