[Question] CGObject_SetFacing menu

Shout-Out

User Tag List

Results 1 to 12 of 12
  1. #1
    Azzie2k8's Avatar Member
    Reputation
    11
    Join Date
    Apr 2009
    Posts
    190
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Question] CGObject_SetFacing

    Hi,
    first off I know there are couple of Threads that concern facing but none do really touch this or even solve this issue so I hope I am not breaking the rules(Yes, I read them ).
    Currently I am trying to set my facing on the current target with the help of CGObject_SetFacing. My Problem is that it has no effect when I call it. No Exceptions, no crashs, no changes in WoW. I am sick of it now and want to see if you guys maybe know whats wrong.

    I am using Apoc's WhiteMagic and managed injection. Thanks to Robske007a for showing/helping me with everything.


    Here is how I try to call the function.
    Code:
            [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
            public delegate void CGObject_C__SetFacing(IntPtr __This, float Angle);
            private static Hooks.CGObject_C__SetFacing _SetFacing;
    
            public float Rotation
            {
                get { return Bot.Memory.Read<float>(((uint)ObjPtr + 0x7A8)); }
    
                set
                {
                    try
                    {
                        if (_SetFacing == null)
                        {
                            _SetFacing = Bot.Memory.RegisterDelegate<Hooks.CGObject_C__SetFacing>(Statics.CGObject_SetFacing);
                        }
                        if (ObjPtr == IntPtr.Zero)
                            throw new NullReferenceException("SetFacing invoked on an invalid Object");
                        _SetFacing(this, value);
                    }
                    catch (Exception Ex)
                    {
                        Log.ShowException(Ex);
                    }
                }
            }
    Here is the rest that sets the facing
    Code:
            public static void FaceTarget()
            {
                if (Bot.Me.TargetGuid != 0)
                {
                    Bot.Target = (WoWUnit)ObjectManager.GetObjectByGuid(Bot.Me.TargetGuid);
                    // Calculate Facing
    
                    float DistanceY = Bot.Me.WowPoint.X - Bot.Target.WowPoint.X;
                    float DistanceX = Bot.Me.WowPoint.Y - Bot.Target.WowPoint.Y;
    
                    //Note that wow uses X Y different to the normal math !
    
                    double ATan = Math.Abs(Math.Atan(DistanceX / DistanceY));
    
                    double TotalShouldFace = 0;
    
                    if (DistanceX < 0)
                    {
                        if (DistanceY > 0)
                        {
                            TotalShouldFace = (2 * Math.PI) - ATan;
                        }
                        else
                        {
                            TotalShouldFace = ATan;
                        }
                    }
                    else
                    {
                        if (DistanceY > 0)
                        {
                            TotalShouldFace = Math.PI + ATan;
                        }
                        else
                        {
                            TotalShouldFace = Math.PI - ATan;
                        }
                    }
                    Bot.Me.Rotation = (float)TotalShouldFace;
                }
            }
    Any Information is welcome

    [Question] CGObject_SetFacing
  2. #2
    caytchen's Avatar Contributor
    Reputation
    138
    Join Date
    Apr 2007
    Posts
    162
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, It would be helpful to know what SetFacing you exactly use. Everybody seems to use a different one around here.

    On the other hand, you're calling it wrong.

    Originally Posted by Azzie2k8
    _SetFacing(this, value);
    You're passing this, which is an object of the wrapper class you built around the real class. You need to pass ObjPtr as this. (I'm just dazzled how you managed to compile that)

  3. #3
    Azzie2k8's Avatar Member
    Reputation
    11
    Join Date
    Apr 2009
    Posts
    190
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by caytchen View Post
    First of all, It would be helpful to know what SetFacing you exactly use. Everybody seems to use a different one around here.

    Thanks for the reply. I am using this CGObject_SetFacing = 0x007EB5C0; function.


    Originally Posted by caytchen View Post
    On the other hand, you're calling it wrong.

    You're passing this, which is an object of the wrapper class you built around the real class. You need to pass ObjPtr as this. (I'm just dazzled how you managed to compile that)
    Since I am using Apoc's Object Manager I am actually able to pass it this way.

    Code:
        public class WoWObject
        {
            internal WoWObject(IntPtr objPtr)
            {
                ObjPtr = objPtr;
            }
    
            public static implicit operator IntPtr(WoWObject obj)
            {
                // Allows us to implicitly cast a WoWObject to an IntPtr (objBase)
                return obj.ObjPtr;
            }
        }

  4. #4
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by caytchen View Post
    First of all, It would be helpful to know what SetFacing you exactly use. Everybody seems to use a different one around here.

    On the other hand, you're calling it wrong.



    You're passing this, which is an object of the wrapper class you built around the real class. You need to pass ObjPtr as this. (I'm just dazzled how you managed to compile that)
    It probably implicitly casts to IntPtr.

    If you're using the SetFacing function I think you're using, you need to pass *(this + 0xD, not 'this'. this + 0xD8 has a pointer to the movement struct.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  5. #5
    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)
    Implicit operators. Presumably his object structure is based around some code Apoc posted (and what is most likely a fairly common pattern with the C# devs writing bots here) that includes something along the lines of:
    Code:
    class WoWObject {
        ...
        public static implicit operator IntPtr(WoWObject obj) {
            return obj.ObjPtr; // or something similar
        }
    }
    ..edit.. and dammit, beaten again :P

  6. #6
    Azzie2k8's Avatar Member
    Reputation
    11
    Join Date
    Apr 2009
    Posts
    190
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    It probably implicitly casts to IntPtr.
    True

    Originally Posted by MaiN View Post
    If you're using the SetFacing function I think you're using, you need to pass *(this + 0xD, not 'this'. this + 0xD8 has a pointer to the movement struct.
    Cannot confirm that but thanks for the hint. I tried but it didn't help besides causing an access violation.

  7. #7
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then tell us what the address of your "CGObject__SetFacing" function is.
    Also, your math is very ****ed up. All you have to do is basically:

    float requiredFacing = (float)Math.Atan2(faceTarget.Y - me.Y, faceTarget.X - me.X);
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  8. #8
    Azzie2k8's Avatar Member
    Reputation
    11
    Join Date
    Apr 2009
    Posts
    190
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    Then tell us what the address of your "CGObject__SetFacing" function is.
    Also, your math is very ****ed up. All you have to do is basically:

    float requiredFacing = (float)Math.Atan2(faceTarget.Y - me.Y, faceTarget.X - me.X);
    I already did in the third post
    Thanks for the reply. I am using this CGObject_SetFacing = 0x007EB5C0; function.
    Thanks for the stuff with the math. I didnt know about atan2 yet. I know that may be a sign of stupidity or something but now I know, thanks.

  9. #9
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the function at 0x7EB570 with *(this + 0xD as 'this'.
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  10. #10
    Azzie2k8's Avatar Member
    Reputation
    11
    Join Date
    Apr 2009
    Posts
    190
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    Try the function at 0x7EB570 with *(this + 0xD as 'this'.
    Just so I get this right. You want to me to call it this way ?
    Code:
    _SetFacing((IntPtr)((uint)this.ObjPtr + (uint)0xD8), value);
    because this is causing an exception

    Exception:
    Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    StackTrace:
    at Framework.Hooks.CGObject_C__SetFacing.Invoke(IntPtr __This, Single Angle)
    at Framework.WoWUnit.set_Rotation(Single value)
    maybe I misunderstood you...

  11. #11
    MaiN's Avatar Elite User
    Reputation
    335
    Join Date
    Sep 2006
    Posts
    1,047
    Thanks G/R
    0/10
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Azzie2k8 View Post
    Just so I get this right. You want to me to call it this way ?
    Code:
    _SetFacing((IntPtr)((uint)this.ObjPtr + (uint)0xD8), value);
    because this is causing an exception



    maybe I misunderstood you...
    You did, you are not dereferencing the pointer.
    *(IntPtr*)((uint)this.ObjPtr + (uint)0xD
    [16:15:41] Cypher: caus the CPU is a dick
    [16:16:07] kynox: CPU is mad
    [16:16:15] Cypher: CPU is all like
    [16:16:16] Cypher: whatever, i do what i want

  12. #12
    Azzie2k8's Avatar Member
    Reputation
    11
    Join Date
    Apr 2009
    Posts
    190
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by MaiN View Post
    You did, you are not dereferencing the pointer.
    *(IntPtr*)((uint)this.ObjPtr + (uint)0xD
    Seems like it is working although I dont get why the first approach didnt work. Anyways thank you very much... +Rep

Similar Threads

  1. Model Changing Question
    By MasterYuke in forum World of Warcraft General
    Replies: 6
    Last Post: 09-17-2006, 09:56 PM
  2. Couple Private Server questions
    By Jboz in forum World of Warcraft General
    Replies: 21
    Last Post: 07-26-2006, 07:37 PM
  3. Sorry..newb mail question
    By nolbishop in forum World of Warcraft General
    Replies: 2
    Last Post: 06-07-2006, 07:21 PM
  4. Question..
    By janzi9 in forum Community Chat
    Replies: 3
    Last Post: 04-02-2006, 10:20 AM
  5. A GALB question
    By bassman in forum World of Warcraft General
    Replies: 4
    Last Post: 03-28-2006, 09:49 AM
All times are GMT -5. The time now is 04:29 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