943,885 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 574
  • C++ RSS
Sep 4th, 2008
0

Problem with DLL i'm coding for a game

Expand Post »
Hello,
Usually I can find solutions to problems that seem to arise when I'm coding for this game, but I'm stumped on why this is happening..

So I found out how to get the text from the last line of the text box on this game, and I want to separate the player name and what they said and store them in different char arrays.

So I made multiple variances of what I think would work, but they all seem to make the same thing happen; they make the last thing that was said disappear! I'm thinking that I'm misunderstanding something so I'm hoping one of you guys could help me out on this.


Here is the source code:
C++ Syntax (Toggle Plain Text)
  1. struct PlayerAnswer{
  2. const char* Player;
  3. const char* Answer;
  4. };
  5.  
  6. int GetLineCount()
  7. {
  8. DWORD* StageTextClassP = (DWORD*)StageTextClass;
  9. int theLineCount = 0;
  10. __asm{
  11. mov ecx, StageTextClassP;
  12. mov eax, 0x004015F0;
  13. call eax;
  14. mov theLineCount, eax;
  15. }
  16. return theLineCount;
  17. }
  18.  
  19. char* GetLastText()
  20. {
  21. DWORD* StageTextClassP = (DWORD*)StageTextClass;
  22. char* textLineText;
  23. int lineCount = GetLineCount()-2;
  24. textLineText = (char*)malloc(255);
  25. __asm{
  26. mov ecx, StageTextClassP;
  27. mov eax, 0x0056EC10;
  28. push lineCount;
  29. call eax;
  30. mov textLineText, eax;
  31. }
  32. return textLineText;
  33. }
  34.  
  35.  
  36. PlayerAnswer GetLastPlayerAnswer()
  37. {
  38. PlayerAnswer pAnswer;
  39. if(string(GetLastText()).find(':') != string::npos)
  40. {
  41. char* plName = strtok(GetLastText(), ":");
  42. char* plAnswer = strtok(NULL, "\0");
  43. pAnswer.Player=plName;
  44. pAnswer.Answer=plAnswer;
  45. return pAnswer;
  46. }
  47. pAnswer.Answer="a";
  48. pAnswer.Player="a";
  49. return pAnswer;
  50.  
  51. }
Oh, and here's pictures on before and after what it looks like:

http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg

Is it a problem with pointers or something? I'm soo confused
Last edited by Tishiablo; Sep 4th, 2008 at 5:33 pm. Reason: added code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tishiablo is offline Offline
3 posts
since Sep 2008
Sep 4th, 2008
0

Re: Problem with DLL i'm coding for a game

Looks like you have some Assembly code mixed in with the GetLineCount () and GetLastText () functions. I have no idea whether those functions are correct or not. In addition, I'm not familiar enough with Windows functions and DWORD, plus I have to relearn malloc every time I use it, which isn't often, so again, I can't comment on those two functions except to say that if there is not a good reason to use C and Assembly code, I would go with C++ code and use C++-strings rather than C-strings and use new rather than malloc .

I rewrote your GetText () function so I could use and try out the GetLastPlayerAnswer() function and as far as I can tell, it seems to work, at least if I understand correctly what it's supposed to do. Here is the program I tested:

C++ Syntax (Toggle Plain Text)
  1. #include <string>
  2. #include <iostream>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. struct PlayerAnswer
  8. {
  9. const char* Player;
  10. const char* Answer;
  11. };
  12.  
  13.  
  14. char* GetLastText()
  15. {
  16. char* someText = new char[8];
  17. strcpy (someText, "Bob:Yes");
  18. return someText;
  19. }
  20.  
  21.  
  22. PlayerAnswer GetLastPlayerAnswer()
  23. {
  24. PlayerAnswer pAnswer;
  25.  
  26. if(string(GetLastText()).find(':') != string::npos)
  27. {
  28. char* plName = strtok(GetLastText(), ":");
  29. char* plAnswer = strtok(NULL, "\0");
  30. pAnswer.Player=plName;
  31. pAnswer.Answer=plAnswer;
  32. return pAnswer;
  33. }
  34.  
  35. pAnswer.Answer="a";
  36. pAnswer.Player="a";
  37. return pAnswer;
  38. }
  39.  
  40.  
  41. int main ()
  42. {
  43. PlayerAnswer pa = GetLastPlayerAnswer ();
  44. cout << "player = " << pa.Player << endl;
  45. cout << "answer = " << pa.Answer << endl;
  46.  
  47. return 0;
  48. }

I think your best step is to really narrow down where exactly the problem is. Put some debugging statements in after the call to the GetLastText () function and make sure it is returning what you want it to. If not, put some debugging code in to make sure that the GetLineCount () function does what it is supposed to do. Once you narrow down the exact function where the problem is located, go from there. Like I said, your GetLastPlayerAnswer () function appears to work to me, or at least it did with my example.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Sep 4th, 2008
0

Re: Problem with DLL i'm coding for a game

ha silly me I forgot to point out that everything did work fine until i had made GetLastPlayerAnswer. Could it be because I'm directly working off of the char* returned? if so, how would I fix that?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tishiablo is offline Offline
3 posts
since Sep 2008
Sep 4th, 2008
0

Re: Problem with DLL i'm coding for a game

Click to Expand / Collapse  Quote originally posted by Tishiablo ...
ha silly me I forgot to point out that everything did work fine until i had made GetLastPlayerAnswer. Could it be because I'm directly working off of the char* returned? if so, how would I fix that?

Run the program I posted and see if that function works correctly. It should split the string "Bob:Yes" into "Bob" and "Yes" and put it into a PlayerName variable, which I thought was the goal. Does it do that for you? Is that what you are looking for? If "Bob:Yes" works and some other string doesn't, list that string that doesn't work.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Sep 4th, 2008
0

Re: Problem with DLL i'm coding for a game

Run the program I posted and see if that function works correctly. It should split the string "Bob:Yes" into "Bob" and "Yes" and put it into a PlayerName variable, which I thought was the goal. Does it do that for you? Is that what you are looking for? If "Bob:Yes" works and some other string doesn't, list that string that doesn't work.
Yes that's what it was supposed to do, but the problem I was having was this:

http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg

You see how the text after the char name is removed? I want it to stay there.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tishiablo is offline Offline
3 posts
since Sep 2008
Sep 4th, 2008
0

Re: Problem with DLL i'm coding for a game

Click to Expand / Collapse  Quote originally posted by Tishiablo ...
Yes that's what it was supposed to do, but the problem I was having was this:

http://i37.tinypic.com/11lr3hw.jpg
http://i38.tinypic.com/rc91qw.jpg

You see how the text after the char name is removed? I want it to stay there.

Well, then my guess is that your problem is elsewhere, in code that you haven't posted. Note that this function:

C++ Syntax (Toggle Plain Text)
  1. PlayerAnswer GetLastPlayerAnswer()
  2. {
  3. PlayerAnswer pAnswer;
  4.  
  5. if(string(GetLastText()).find(':') != string::npos)
  6. {
  7. char* plName = strtok(GetLastText(), ":");
  8. char* plAnswer = strtok(NULL, "\0");
  9. pAnswer.Player=plName;
  10. pAnswer.Answer=plAnswer;
  11. return pAnswer;
  12. }
  13.  
  14. pAnswer.Answer="a";
  15. pAnswer.Player="a";
  16. return pAnswer;
  17. }

doesn't display anything anywhere; it merely splits the string in two. So somewhere after the call to this function, if you want to actually display the two broken strings, you have to do so by appending it to the text box or however you do it. But it appears that GetLastPlayerAnswer () is not intended to display anything. It merely breaks the string in two and it appears to be working. If it's also supposed to append the text to the text box, you'll have to add that part.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problems with reading from a sequential file
Next Thread in C++ Forum Timeline: creat file for data in output folder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC