You love me ulong time? menu

Shout-Out

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    EmilyStrange's Avatar Active Member
    Reputation
    34
    Join Date
    Jul 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    You love me ulong time?

    My room-mate was kvetching at me about my use of "ulong" in my code to represent a GUID within the World of Warcraft game client. I pointed out to her that I also had a structure that worked like a union too, in case I needed to access the low-word or high-word for anything, but she just claimed it was an ugly hack (she can get really crabby around the holidays), especially when it came to assigning and reading the actual GUID because of the indirection operator that was needed.

    To appease her I decided to modify my structure to handle implicit assignment and conversion between the "ulong"-type, cleaning up the code, and giving explicit meaning to the use of "ulong" anywhere in the code base.

    Here's my solution, it can be dropped in to your project, and instead of using "ulong" to represent your 64-bit GUIDs, you can just use this structure.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.InteropServices;
    
    namespace WarcraftVoodoo
    {
        [StructLayout(LayoutKind.Explicit)]
        public struct GameGUID
        {
            [FieldOffset(0)]
            public UInt64 GUID;
    
            [FieldOffset(0)]
            public UInt32 LowWord;
    
            [FieldOffset(4)]
            public UInt32 HighWord;
    
            public static implicit operator GameGUID(ulong rhs)
            {
                GameGUID g = new GameGUID();
                g.GUID = rhs;
                return g;
            }
    
            public static implicit operator ulong(GameGUID rhs)
            {
                return rhs.GUID;
            }
    
        }
    
    }
    To use the above in your code:

    Code:
    GameGUID targetGUID = 64646464; // made up GUID to illustrate point
    m_gameClient.Injection.SelectUnit(targetGUID); // conversion to ulong for the function call is implicit
    Let me know if I overlooked anything.

    You love me ulong time?
  2. #2
    Mirror's Avatar Contributor
    Reputation
    259
    Join Date
    Nov 2006
    Posts
    2,602
    Thanks G/R
    0/0
    Trade Feedback
    2 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. Me love you long time.
    THIS SIGNATURE IS IN VIALOATION OF SITE RULES, PLEASE FIX ME!
    -Fault

  3. #3
    Scorpiona's Avatar Active Member
    Reputation
    17
    Join Date
    Mar 2009
    Posts
    42
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While I'm not sure why this would ever be useful in the context of WoW, why not use a proper way like this instead of trying to replace a core valuetype with your own struct? >.>

    edit: here's another one to help you
    Last edited by Scorpiona; 01-01-2010 at 09:03 PM.

  4. #4
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's no reason to even bother creating your own struct IMHO. The only times you'd need to check the high/low bytes of a GUID are very sparse; in which a simple bit shift would do fine.

    Tell your friend to stop being an idiot and making things far more complex than they need to be.

    Edit; even to WoW, they use a ulong (unsigned long long). So the difference here is absolutely 0.

    Only reason WoW uses 2 different DWORDs in memory; is because x86 processes can't store 64 bit values in 1 register. So it's split into 2.

    Edit; also with your approach; you can't use equality operators [you've forgotten to add them]

    So if I wanted to do something like,

    Code:
    if(myTarget.Guid != 0)
    I wouldn't be able to.

    As I said; a lot of fluff for no apparent reason.
    Last edited by Apoc; 01-01-2010 at 09:08 PM.

  5. #5
    EmilyStrange's Avatar Active Member
    Reputation
    34
    Join Date
    Jul 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Scorpiona View Post
    While I'm not sure why this would ever be useful in the context of WoW, why not use a proper way like this instead of trying to replace a core valuetype with your own struct? >.>

    edit: here's another one to help you
    There are many cats. And there are many skinners.

    But to address your response:
    1) Shifting and masking, even in pure assembly language, is less efficient than a simple four-byte offset addition to a register.

    But that point is completely secondary to:
    2) You missed the point of the post completely.

  6. #6
    EmilyStrange's Avatar Active Member
    Reputation
    34
    Join Date
    Jul 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @apoc: From your response...

    I am 100% certain that the World of Warcraft game client uses a typedef to make the use of long long (64-bit integer) an explicit statement within the source code. C# doesn't support typedefs and the standard way of defining them, that most people agree on, is to use a struct.

    The high/low union "comes for free" with the adoption of a union. For the few times that it is necessary to access the high and low words, I agree that bit-shifting, or accessing union members, it is a total toss-up. However, unless you have a function that explicitly does the bit shifting, it would not be clear in the code what it is the programmer is doing. "Why are you bit shifting here? What was the purpose of this?" Good programmers write code that is as much self-documenting as the documenting itself.

    It is evident from your response with regard to testing for equality that you chose to actually pass judgement on my solution rather than try it out first.

    P.S. I'll be sure to let her know that you think she is an idiot. I am confident one of the PMs on the .NET Framework team will hold your opinion about her skill-set in as high regard as I do when it comes to your opinion about mine.

  7. #7
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by EmilyStrange View Post
    @apoc: From your response...

    I am 100% certain that the World of Warcraft game client uses a typedef to make the use of long long (64-bit integer) an explicit statement within the source code. C# doesn't support typedefs and the standard way of defining them, that most people agree on, is to use a struct.

    The high/low union "comes for free" with the adoption of a union. For the few times that it is necessary to access the high and low words, I agree that bit-shifting, or accessing union members, it is a total toss-up. However, unless you have a function that explicitly does the bit shifting, it would not be clear in the code what it is the programmer is doing. "Why are you bit shifting here? What was the purpose of this?" Good programmers write code that is as much self-documenting as the documenting itself.

    It is evident from your response with regard to testing for equality that you chose to actually pass judgement on my solution rather than try it out first.

    P.S. I'll be sure to let her know that you think she is an idiot. I am confident one of the PMs on the .NET Framework team will hold your opinion about her skill-set in as high regard as I do when it comes to your opinion about mine.
    I repeat; why bother creating a struct that does nothing more than add overhead, and typing, when it's not necessary? If you've got so much code that specifically uses the hi/low bytes of a GUID, then you're doing something wrong, or your friend is anal-retentive and can't comprehend bit-shifts on the fly. (If such is the case; they have no reason doing any type of reversing, or game programming [which is what we do here for the most part])

    Also; good programmers know when to WRITE ****ING COMMENTS when code is ambiguous. (Which it never is within the context of WoW, and shifting GUIDs)

    My point still stands (on all accounts). Nor do I care what/who your friend is, or who their friends are, or their friend's friend's dog's sister-in-law.
    Last edited by Apoc; 01-04-2010 at 11:42 PM.

  8. #8
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    [SNIP]
    My point still stands (on all accounts). Nor do I care what/who your friend is, or who they're friends are, or they're friend's friend's dog's sister-in-law.
    First off, "their", not "they're". Noob.

    Second, wouldn't that mean that your friend's friend's dog got married?

  9. #9
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    First off, "their", not "they're". Noob.

    Second, wouldn't that mean that your friend's friend's dog got married?
    Yes. Yes it would.

  10. #10
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Apoc View Post
    Yes. Yes it would.

  11. #11
    EmilyStrange's Avatar Active Member
    Reputation
    34
    Join Date
    Jul 2009
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @cyper: Apoc had the correct usage of "their."

    @apoc: All I hear is "blah blah blah" from someone who is trying very hard to be confrontational.
    Last edited by EmilyStrange; 01-05-2010 at 03:04 AM.

  12. #12
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by EmilyStrange View Post
    @cyper: Apoc had the correct usage of "their."

    @apoc: All I hear is "blah blah blah" from someone who is trying very hard to be confrontational.
    No, he didn't. He modified his post.

    He said "they're" originally.

    EDIT:

    To clarify, this is what he originally said:
    "Nor do I care what/who your friend is, or who they're friends are, or they're friend's friend's dog's sister-in-law."

    Which, when expanded, results in:
    "Nor do I care what/who your friend is, or who they are friends are, or they are friend's friend's dog's sister-in-law."

    Which is obviously incorrect.

    Now do you know why I said in the other thread that ninja-editing is a bad idea?

    P.S. Shame on you Apoc, you should know better, or at least tag your edit as "spelling/grammar fix".

  13. #13
    Nesox's Avatar ★ Elder ★
    Reputation
    1280
    Join Date
    Mar 2007
    Posts
    1,238
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    No, he didn't. He modified his post.

    He said "they're" originally.

    EDIT:

    To clarify, this is what he originally said:
    "Nor do I care what/who your friend is, or who they're friends are, or they're friend's friend's dog's sister-in-law."

    Which, when expanded, results in:
    "Nor do I care what/who your friend is, or who they are friends are, or they are friend's friend's dog's sister-in-law."

    Which is obviously incorrect.

    Now do you know why I said in the other thread that ninja-editing is a bad idea?

    P.S. Shame on you Apoc, you should know better, or at least tag your edit as "spelling/grammar fix".
    omg you really must be bored shitless if ure hunting bad grammar ! hsnap:

  14. #14
    Apoc's Avatar Angry Penguin
    Reputation
    1388
    Join Date
    Jan 2008
    Posts
    2,750
    Thanks G/R
    0/13
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by EmilyStrange View Post
    @cyper: Apoc had the correct usage of "their."

    @apoc: All I hear is "blah blah blah" from someone who is trying very hard to be confrontational.
    I ninja-edited my post, he was correct. (No sleep is a bad thing)

    Also; I'm not being confrontational. You're making baseless statements that have nothing to do with the topic at hand. You've failed to provide a reason for using your struct at all from within C# code. Until you provide a concrete reason, other than 'code should be self documenting' (which is usually true, however, that's why comments are available in nearly every language), then I'll stop picking at your code. You're reversing a game, and working with a game's memory. It's highly optimized code (compared to standard application code that is. I'm in no way implying WoW is 'incredibly optimized' because we all know it isn't), and being able to figure out the reason for a bit shift while skimming code should be apparent if you're reading the code anyway. This isn't some 'standard' application stuff.

    If you're reversing stuff in, say, IDA, then I can completely agree on your struct. In fact I use a similar struct, only because it makes reversing that much easier. In usual code however; there's no need for it when there's a perfectly viable language-specific replacement. (ulong, long, etc)

  15. #15
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Nesox View Post
    omg you really must be bored shitless if ure hunting bad grammar ! hsnap:
    Only because it's Apoc.

Page 1 of 2 12 LastLast

Similar Threads

  1. AV guide (you will win every time or almst)
    By snowbird in forum World of Warcraft Guides
    Replies: 24
    Last Post: 07-15-2008, 10:19 AM
  2. How much do you love noodles?
    By Cursed in forum Screenshot & Video Showoff
    Replies: 4
    Last Post: 05-05-2008, 12:10 PM
  3. *WARNING* You may want your time back
    By mkeg0dn in forum Screenshot & Video Showoff
    Replies: 21
    Last Post: 01-21-2008, 02:02 PM
All times are GMT -5. The time now is 09:07 AM. 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