Putting all game objects into an array of gameobjets. menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    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)

    Putting all game objects into an array of gameobjets.

    Hi as i was upgrading my fishbot a bit i decided to instead of looking for the fishing bobber directly in the function where all the GameObjects get's dumped i decided to rewrite some of it to make it return an array of Gameobjects here goes:

    first we make a List where we can put all our gameobjects in
    Code:
     List<GameObject> _GameObject = new List<GameObject>();

    here's my gameobject struct that im currently using
    Code:
    public struct GameObject
            {
                public float X;
                public float Y;
                public float Z;
                public ulong GUID;
                public uint BaseAdress;
    
                public override string ToString()
                {
                    return string.Format("X:{0}, Y:{1}, Z:{2}, GUID:0x{3:X016}, BaseAdress:{4:X08}", X, Y, Z, GUID, BaseAdress);
                }
    then after we got ewrything we want in our loop or w/e ure using to get objects we declare a new GameObject.

    Code:
    GameObject curObject = new GameObject();
                    curObject.X = X;
                    curObject.Y = Y;
                    curObject.Z = Z;
                    curObject.GUID = cGUID;
                    curObject.BaseAdress = curObj;
    now curObject contains all info i want for the current object in the list then we add it to the List<GameObject> _GameObject

    Code:
    _GameObject.Add(curObject);
    and finally at the end of our function we declare an array of gameobjects, same size as the list is and then return it.
    Code:
    GameObject[] list = new GameObject[_GameObject.Count];
                _GameObject.CopyTo(list);
    
                return list;
    hope this help's someone. and thx Shyn'd for your wonderful Journal it helped me alot :wave:

    Edit: btw this is in c# but i hope evrybody reading this understand's that

    Putting all game objects into an array of gameobjets.
  2. #2
    mickaldinho's Avatar Member
    Reputation
    13
    Join Date
    Aug 2008
    Posts
    121
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks good man

  3. #3
    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)
    Waste of resources. Why bother looping and copying the entire linked list when all you need is one entry??

    Furthermore, why copy into a list then recopy into an array.

    Just seems like such an inefficient way to do things...

  4. #4
    Shynd's Avatar Contributor
    Reputation
    97
    Join Date
    May 2008
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should use a class instead of a structure. Make the class constrictor take x, y, z, guid, etc., as arguments. Makes code faster and easier to read. And, again, like Cypher said, this would apply nicely to a bot but is slightly overkill for a fishbot.

    Also, a list of class objects would be better than an array of class objects anyway. No need to copy back and forth.
    Last edited by Shynd; 09-21-2008 at 07:22 PM.

  5. #5
    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)
    Originally Posted by Shynd View Post
    Should use a class instead of a structure. Make the class constrictor take x, y, z, guid, etc., as arguments. Makes code faster and easier to read. And, again, like Cypher said, this would apply nicely to a bot but is slightly overkill for a fishbot.

    Also, a list of class objects would be better than an array of class objects anyway. No need to copy back and forth.

    By definition structs are 'lighter' objects than classes so I don't know where you're getting the idea that a class is 'faster'. Easier to read? Yes. Faster? Unlikely. Its not going to be noticeably slower (or even slower at all necessarily) but afaik it would not be faster.


    But yeah. Definately overkill. And Synd, what do you mean it would 'apply nicely to a bot', howso? The only advantage having your own copy of the object list would be that you could redirect accesses to it in WoW to your own list to assist in multithreaded bot programming. (ISXWoW does this) And unless you really know what you're doing than its kinda pointless anyway.

    PS. Structs can have constructors.
    Last edited by Cypher; 09-21-2008 at 10:28 PM.

  6. #6
    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
    Waste of resources. Why bother looping and copying the entire linked list when all you need is one entry??

    Furthermore, why copy into a list then recopy into an array.

    Just seems like such an inefficient way to do things...
    well i like it that way it's the best way i can think of atm. here's one of my function's
    Code:
    public static CorpseObject[] GetCorpseObjects(IntPtr hProcess)
            {
                Object[] Objects = GetObjects(hProcess);
    
                List<CorpseObject> Corpses = new List<CorpseObject>();
                for (int i = 0; i < Objects.Length; i++)
                {
    
                    if (Objects[i].OBJECT_FIELD_TYPE == (int)eObjectType.CORPSE)
                    {
                            float x = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_POS_X));
    
                            float y = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_POS_Y));
    
                            float z = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_POS_Z));
    
                            float facing = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_FACING));
    
                            UInt64 owner = MemoryLib.Memory.ReadUInt64(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_OWNER));
    
                            CorpseObject tempCorpse = new CorpseObject();
                            tempCorpse.CORPSE_FIELD_POS_X = x;
                            tempCorpse.CORPSE_FIELD_POS_Y = y;
                            tempCorpse.CORPSE_FIELD_POS_Z = z;
                            tempCorpse.CORPSE_FIELD_FACING = facing;
                            tempCorpse.CORPSE_FIELD_OWNER = owner;
    
                            Corpses.Add(tempCorpse);
                    }
                }
                CorpseObject[] retVector = new CorpseObject[Corpses.Count];
                Corpses.CopyTo(retVector);
    
                return retVector;
            }
    it return's an array with CorpseObject[] and then u can loop throu it and do w/e u want with the info im open to suggestion's btw. im using your MemoryLib shynd it's much better than WowSharp's MemoryReader but i'll write my own sometime when i got time ive written almost 8 classes so far for my bot.
    im stuck at my xmlparser :yuck: can't get it to read attributes in an element and store them as different values.

    i dont see how a class would help and be more efficent. I prefer working with structs is so much nicer if u got lot's of variables atm i takes about 200ms to read
    and copy all the Descriptors exept ePlayerFields and Unit i havent written them yet.
    :wave:
    l8rz

  7. #7
    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)
    Originally Posted by Nesox View Post
    well i like it that way it's the best way i can think of atm. here's one of my function's
    Code:
    public static CorpseObject[] GetCorpseObjects(IntPtr hProcess)
            {
                Object[] Objects = GetObjects(hProcess);
    
                List<CorpseObject> Corpses = new List<CorpseObject>();
                for (int i = 0; i < Objects.Length; i++)
                {
    
                    if (Objects[i].OBJECT_FIELD_TYPE == (int)eObjectType.CORPSE)
                    {
                            float x = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_POS_X));
    
                            float y = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_POS_Y));
    
                            float z = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_POS_Z));
    
                            float facing = MemoryLib.Memory.ReadFloat(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_FACING));
    
                            UInt64 owner = MemoryLib.Memory.ReadUInt64(hProcess,
                               (MemoryLib.Memory.ReadUInt(hProcess, Objects[i].OBJECT_FIELD_BASEADRESS + 0x08) + (int)eCorpseFields.CORPSE_FIELD_OWNER));
    
                            CorpseObject tempCorpse = new CorpseObject();
                            tempCorpse.CORPSE_FIELD_POS_X = x;
                            tempCorpse.CORPSE_FIELD_POS_Y = y;
                            tempCorpse.CORPSE_FIELD_POS_Z = z;
                            tempCorpse.CORPSE_FIELD_FACING = facing;
                            tempCorpse.CORPSE_FIELD_OWNER = owner;
    
                            Corpses.Add(tempCorpse);
                    }
                }
                CorpseObject[] retVector = new CorpseObject[Corpses.Count];
                Corpses.CopyTo(retVector);
    
                return retVector;
            }
    it return's an array with CorpseObject[] and then u can loop throu it and do w/e u want with the info im open to suggestion's btw. im using your MemoryLib shynd it's much better than WowSharp's MemoryReader but i'll write my own sometime when i got time ive written almost 8 classes so far for my bot.
    im stuck at my xmlparser :yuck: can't get it to read attributes in an element and store them as different values.

    i dont see how a class would help and be more efficent. I prefer working with structs is so much nicer if u got lot's of variables atm i takes about 200ms to read
    and copy all the Descriptors exept ePlayerFields and Unit i havent written them yet.
    :wave:
    l8rz

    The best way you can think of???? Why bother copying the memory in the first place, just access it directly from WoW....

    Struct/Class/Array/List/Whatever, it doesn't change the fact that what you're doing is a pointless waste of resouces.

  8. #8
    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

    The best way you can think of???? Why bother copying the memory in the first place, just access it directly from WoW....

    Struct/Class/Array/List/Whatever, it doesn't change the fact that what you're doing is a pointless waste of resouces.
    hehe well how would u do it? just make a function that take's what kind of object u want and field?
    edit:
    like u posted in my other therad?
    Code:
    class CGObject_C
    {
    // SNIP
    unsigned int pStorage1;                // 0x0008 - 0x000C
    // SNIP
    }
    
    template<typename T>
    T CGObject_C::GetKnownField(unsigned int Field)
    {
        try
        {
            T* pMyStorage = (T*)(pStorage1);
            return pMyStorage[Field];
        }
        catch (...)
        {
            gpLog->Add("Failed to get field %i", Field);
        }
        return (T)0;
    Last edited by Nesox; 09-22-2008 at 03:34 AM.

  9. #9
    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)
    Originally Posted by Nesox View Post
    hehe well how would u do it? just make a function that take's what kind of object u want and field?
    edit:
    like u posted in my other therad?
    Code:
    class CGObject_C
    {
    // SNIP
    unsigned int pStorage1;                // 0x0008 - 0x000C
    // SNIP
    }
    
    template<typename T>
    T CGObject_C::GetKnownField(unsigned int Field)
    {
        try
        {
            T* pMyStorage = (T*)(pStorage1);
            return pMyStorage[Field];
        }
        catch (...)
        {
            gpLog->Add("Failed to get field %i", Field);
        }
        return (T)0;

    If you're in an injected DLL it's as easy as defining your class and doing some direct pointer arithmetic and access.

    If you're outside the process you can achieve the same thing using ReadProcessMemory. There's no need to copy the memory into an array because by the time you've done that you've already passed the information you require. Furthermore, the linked list is updated fairly often so your copy would become very outdated very fast. (Along with being a pointless resource drain)

  10. #10
    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

    If you're in an injected DLL it's as easy as defining your class and doing some direct pointer arithmetic and access.

    If you're outside the process you can achieve the same thing using ReadProcessMemory. There's no need to copy the memory into an array because by the time you've done that you've already passed the information you require. Furthermore, the linked list is updated fairly often so your copy would become very outdated very fast. (Along with being a pointless resource drain)
    ok, well in one of my earlier projects i used kinda that i had a wrapperclass for ReadProcessMemory the wowsharp memory reader and i put it in a loop that read continous to get x,y,z etc.. and my fishbot reads status of bobber evry time i cast etc.

    i guess it's waste of resources as you said as some values get's outdated very fast .

  11. #11
    Shynd's Avatar Contributor
    Reputation
    97
    Join Date
    May 2008
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post

    By definition structs are 'lighter' objects than classes so I don't know where you're getting the idea that a class is 'faster'. Easier to read? Yes. Faster? Unlikely. Its not going to be noticeably slower (or even slower at all necessarily) but afaik it would not be faster.


    But yeah. Definately overkill. And Synd, what do you mean it would 'apply nicely to a bot', howso? The only advantage having your own copy of the object list would be that you could redirect accesses to it in WoW to your own list to assist in multithreaded bot programming. (ISXWoW does this) And unless you really know what you're doing than its kinda pointless anyway.

    PS. Structs can have constructors.
    I meant faster to write / access (in my opinion). Instead of putting object.X = whatever and so forth, just a simple constructor and then add whatever class methods necessary to it (while, yes, structs can have constructors, I don't see any reason to pick a struct over a class). Posting on my phone == my laziness sometimes causes me to leave out explanations

    And the way I had my external bot working, before I scrapped it, was having one thread constantly reading up-to-date information from memory and changing around my list of objects while the other thread handled bot logic and whatnot. I made sure to lock access to the object list whenever it was being written or accessed, so it was thread-safe, but it saved me from having to make sure my information was up-to-date at the top of every bot loop or before this action or that action or whatever. I could just iterate through each object in the list, find the nearest one, etc., and information would be updated for me in the background without me having to think about it (emulating what it's like to be injected into the process as closely as possible).

  12. #12
    argh44z's Avatar Member
    Reputation
    19
    Join Date
    Nov 2007
    Posts
    93
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of a list/array use a map/associative array/dictionary (sorry, don't know what they're called in C#) with the key being a guid.

    What my fishbot/bot/minimap does is basically what the approach that shynd describes. One thread reads the objects from memory and stores them in an associative array protected with a mutex. Another thread does rendering of the minimap based on the current state. A third thread controls bot behavior based on the object array and other state.

  13. #13
    Shynd's Avatar Contributor
    Reputation
    97
    Join Date
    May 2008
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, an IDictionary object of your own making would be probably the best approach. I SUPPOSE you could just use the Hashtable inside System.Collections but writing your own would be better.

  14. #14
    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)
    Originally Posted by Nesox View Post
    ok, well in one of my earlier projects i used kinda that i had a wrapperclass for ReadProcessMemory the wowsharp memory reader and i put it in a loop that read continous to get x,y,z etc.. and my fishbot reads status of bobber evry time i cast etc.

    i guess it's waste of resources as you said as some values get's outdated very fast .
    A loop with ReadProcessMemory is exactly how I'd do it.

    Originally Posted by Shynd View Post
    I meant faster to write / access (in my opinion). Instead of putting object.X = whatever and so forth, just a simple constructor and then add whatever class methods necessary to it (while, yes, structs can have constructors, I don't see any reason to pick a struct over a class). Posting on my phone == my laziness sometimes causes me to leave out explanations

    And the way I had my external bot working, before I scrapped it, was having one thread constantly reading up-to-date information from memory and changing around my list of objects while the other thread handled bot logic and whatnot. I made sure to lock access to the object list whenever it was being written or accessed, so it was thread-safe, but it saved me from having to make sure my information was up-to-date at the top of every bot loop or before this action or that action or whatever. I could just iterate through each object in the list, find the nearest one, etc., and information would be updated for me in the background without me having to think about it (emulating what it's like to be injected into the process as closely as possible).

    There's no speed difference, check your compilers output.


    Originally Posted by argh44z View Post
    Instead of a list/array use a map/associative array/dictionary (sorry, don't know what they're called in C#) with the key being a guid.

    What my fishbot/bot/minimap does is basically what the approach that shynd describes. One thread reads the objects from memory and stores them in an associative array protected with a mutex. Another thread does rendering of the minimap based on the current state. A third thread controls bot behavior based on the object array and other state.
    Maps are even slower than lists, the whole point is we're trying to avoid that overhead. Also, wtf are you 'protecting' them with a mutex for? All you need is a single thread to loop through the linked list in WoW"s memory to pull out the information you neeed. You're really overcomplicating things.

  15. #15
    Shynd's Avatar Contributor
    Reputation
    97
    Join Date
    May 2008
    Posts
    393
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The mutex is used because one thread in his program will be accessing the list while another will be writing to it. Bad things happen if both happen at the same time.


    And, again, because I'm apparently really, really bad at explaining things today, I meant from a code-writing standpoint, not from memory-write/access. It's easier and faster to add features to a class and access members of a class, in my opinion, than a structure. I know that classes are not faster than structures--though to what degree that is true in C#, I'm not actually sure--but the speed difference is measured in nanoseconds, these days, so the 'quicker' I'm talking about is time spent typing lines of code.

Page 1 of 2 12 LastLast

Similar Threads

  1. Is it possible to change a weapon (item) into a chest (game object)?
    By Jameswow123 in forum WoW ME Questions and Requests
    Replies: 8
    Last Post: 07-20-2010, 02:24 AM
  2. how do i put my custom item into the game?
    By soapygrinda in forum World of Warcraft Emulator Servers
    Replies: 6
    Last Post: 02-11-2008, 04:56 PM
  3. [Release] GM Handbook - ALL ID's of Npc , Game Object, Recall , GO, Skills and Items
    By mafiaboy in forum World of Warcraft Emulator Servers
    Replies: 8
    Last Post: 12-24-2007, 09:30 PM
  4. Burning Crusade: All Races Changed Into Blood Elf/Draenei *READY TO USE*
    By SandLOL in forum World of Warcraft Model Editing
    Replies: 102
    Last Post: 12-02-2006, 05:58 PM
All times are GMT -5. The time now is 04:47 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