[Help][C++] Need help with array of pointers menu

User Tag List

Results 1 to 4 of 4
  1. #1
    prospectingemu's Avatar Member
    Reputation
    15
    Join Date
    Mar 2014
    Posts
    49
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Help][C++] Need help with array of pointers

    Edit: Solved please close

    Hi guys, I'm trying to convert DaCoder's C# object manager to c++ and having some issues. Right now calling:

    Code:
    ListWoWObjects * tempList = new ListWoWObjects();
    WoWObject tempObj;
    
    tempObj = *tempList->get(0);
    
    cout << tempObj.Name;
    Is giving me a blank char (All wow objects are being initialised as "null object").

    Edit: Should have mentioned this is a dll.

    Code:
    BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwAttached, LPVOID lpvReserved)
    {
    	if (dwAttached == DLL_PROCESS_ATTACH) {
    		CreateThread(NULL, 0, &Main_Thread, NULL, 0, NULL);
    		RedirectIOToConsole();
    	}
    	return 1;
    }

    WoWObject.h

    Code:
    #ifndef __WOWOBJECT_H__
    #define __WOWOBJECT_H__
    
    #include <windows.h>
    #include <string>
    
    
    typedef unsigned long ulong;
    typedef unsigned int uint;
    
    enum ObjType : uint
    {
    	OT_NONE = 0,
    	OT_ITEM = 1,
    	OT_CONTAINER = 2,
    	OT_UNIT = 3,
    	OT_PLAYER = 4,
    	OT_GAMEOBJ = 5,
    	OT_DYNOBJ = 6,
    	OT_CORPSE = 7,
    	OT_FORCEDWORD = 0xFFFFFFFF
    };
    
    enum GameObjectType : uint
    {
    	Door = 0,
    	Button = 1,
    	QuestGiver = 2,
    	Chest = 3,
    	Binder = 4,
    	Generic = 5,
    	Trap = 6,
    	Chair = 7,
    	SpellFocus = 8,
    	Text = 9,
    	Goober = 0xa,
    	Transport = 0xb,
    	AreaDamage = 0xc,
    	Camera = 0xd,
    	WorldObj = 0xe,
    	MapObjTransport = 0xf,
    	DuelArbiter = 0x10,
    	FishingNode = 0x11,
    	Ritual = 0x12,
    	Mailbox = 0x13,
    	AuctionHouse = 0x14,
    	SpellCaster = 0x16,
    	MeetingStone = 0x17,
    	Unkown18 = 0x18,
    	FishingPool = 0x19,
    	FORCEDWORD = 0xFFFFFFFF,
    };
    
    class WoWObject{
    public:
    
    	WoWObject();
    	~WoWObject();
    
    
    	ulong Guid;
    	ulong SummonedBy;
    	float XPos;
    	float YPos;
    	float ZPos;
    	float Rotation;
    	byte ComboPoints;
    	int Energy;
    	int Mana;
    	uint BaseAddress;
    	uint UnitFieldsAddress;
    	short Type;
    	std::string Name;
    	uint id;
    
    	uint CurrentHealth;
    	uint MaxHealth;
    	uint CurrentEnergy;
    	uint MaxEnergy;
    	uint Level;
    	int CurrentForm;
    
    	uint GameObjectType;
    
    };
    
    #endif

    WoWObject.cpp
    Code:
    #include "WoWObject.h"
    
    WoWObject::WoWObject(){
    	ulong Guid = 0;
    	ulong SummonedBy = 0;
    	float XPos = 0;
    	float YPos = 0;
    	float ZPos = 0;
    	float Rotation = 0;
    	byte ComboPoints = 0;
    	int Energy = 0;
    	int Mana = 0;
    	uint BaseAddress = 0;
    	uint UnitFieldsAddress = 0;
    	short Type = 0;
    	std::string Name = "null object";
    	uint id = 0;
    
    	uint CurrentHealth = 0;
    	uint MaxHealth = 0;
    	uint CurrentEnergy = 0;
    	uint MaxEnergy = 0;
    	uint Level = 30;
    	int CurrentForm = 0;
    
    	uint GameObjectType = 0;
    }
    
    WoWObject::~WoWObject(){
    }
    ListWoWObjects.h

    Code:
    #ifndef __LISTWOWOBJECTS_H__
    #define __LISTWOWOBJECTS_H__
    
    #include "WoWObject.h"
    
    class ListWoWObjects{
    public:
    	ListWoWObjects();
    	~ListWoWObjects();
    	WoWObject Head;
    	void add(WoWObject *);
    	WoWObject * get(int);
    	int count();
    	WoWObject * pointerArray(int);
    	WoWObject * objects;
    private:
    	int size;
    };
    
    #endif
    ListWoWObjects.cpp

    Code:
    #include "ListWoWObjects.h"
    
    WoWObject * objects();
    
    ListWoWObjects::ListWoWObjects(){
    	objects = pointerArray(10000); //Yes I know this is stupid, will be using a function
    	size = 0;                                //to have the function grow dynamically later
    }
    
    ListWoWObjects::~ListWoWObjects(){
    }
    
    void ListWoWObjects::add(WoWObject *obj){
    	objects[size] = *obj;
    	size++; //Again this function is stupid, it will be changed
    }
    
    WoWObject * ListWoWObjects::get(int pos){
    	return  &objects[pos];
    }
    
    int ListWoWObjects::count(){
    	return size;
    }
    
    //Trying to create an array of pointers in the heap  to keep track of all objects
    
    WoWObject * ListWoWObjects::pointerArray(int n){
    	WoWObject *returnValue = new WoWObject[n]; 
    	for (int i = 0; i < n; i++){
    		returnValue[i] = * new WoWObject();
    	}
    	return returnValue;
    }
    Last edited by prospectingemu; 03-18-2014 at 10:13 PM.

    [Help][C++] Need help with array of pointers
  2. #2
    hamburger12's Avatar Contributor CoreCoins Purchaser
    Reputation
    87
    Join Date
    Jan 2010
    Posts
    297
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't use a std::list or std::vector for it?

  3. #3
    prospectingemu's Avatar Member
    Reputation
    15
    Join Date
    Mar 2014
    Posts
    49
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I probably should/will. The problem i'm having is with WoWObject atm though

    Code:
    	WoWObject * tempObj = new WoWObject();
    	cout << tempObj->CurrentForm<< endl;
    Is returning a really big negative value. Can you point out where i've gone wrong here?

    Edit: just tested a few more things, is it possible I'm just missing a cast or something here? The form (meant to be an int) at 600 is the same value as from 0. Just the wrong values
    Last edited by prospectingemu; 03-18-2014 at 06:28 PM.

  4. #4
    prospectingemu's Avatar Member
    Reputation
    15
    Join Date
    Mar 2014
    Posts
    49
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nvm I'm just retarded, the WoWObject constructor was assigning them incorrectly - Please close.

Similar Threads

  1. Help with Multi Level Pointers.
    By keldeo in forum Programming
    Replies: 1
    Last Post: 11-30-2013, 08:50 PM
  2. [Bot] Need help with Pointers
    By NanoB in forum WoW Memory Editing
    Replies: 7
    Last Post: 12-03-2010, 09:42 AM
  3. I need help with multi-level pointers in CE
    By Phygar in forum WoW Memory Editing
    Replies: 0
    Last Post: 01-31-2008, 04:38 PM
  4. I need help with CE (pointers)
    By vivec45 in forum World of Warcraft General
    Replies: 0
    Last Post: 08-10-2007, 02:45 AM
  5. need help with shammy talents
    By jason in forum World of Warcraft General
    Replies: 5
    Last Post: 07-19-2006, 02:02 AM
All times are GMT -5. The time now is 04:47 AM. 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