crackdawg Posted June 30, 2009 Share Posted June 30, 2009 (edited) I've been messing with player IDs and noticed they start at 0 and go to random numbers like 32 etc. Trying to scan them crashes the thread after a short run..I guess because of timing or something. Buffer is 24 for the record. if ((GetAsyncKeyState(VK_F8) & 1) != 0) { if(NetworkIsSessionStarted()) { for(u32 i=0; i<=1000; i++){ playerIndex = ConvertIntToPlayerIndex(i); if(GetPlayerName(playerIndex) != "**Invalid**") { LogInfo(GetPlayerName(playerIndex)); itoa(playerIndex,buffer,10); LogInfo(buffer); } } } } Last scan was like this before it crashed the thread: 0,24,25,26,27,28,31 I think there was more but it crashed. Edited June 30, 2009 by crackdawg Link to comment Share on other sites More sharing options...
sjaak327 Posted June 30, 2009 Share Posted June 30, 2009 Well it's kind of obvious that in MP those are indeed random, in SP the playerid is always 0. This is how I get playernames: const ch *name1 =GetPlayerName(1); where playerindex is a value between 0 and 31 (there are a maximum of 32 slots in MP. The player that runs the mod is easily picked up using: u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); const ch *name =GetPlayerName(playerIndex); To get the current host: int host =GetHostId(); There is nothing more to it really, and never crashes for me. Oh and no surpise it crashed after 31, as that would be the maximum possible value. Link to comment Share on other sites More sharing options...
crackdawg Posted June 30, 2009 Author Share Posted June 30, 2009 (edited) Well it's kind of obvious that in MP those are indeed random, in SP the playerid is always 0. This is how I get playernames: const ch *name1 =GetPlayerName(1); where playerindex is a value between 0 and 31 (there are a maximum of 32 slots in MP. The player that runs the mod is easily picked up using: u32 playerIndex = ConvertIntToPlayerIndex(GetPlayerId()); const ch *name =GetPlayerName(playerIndex); To get the current host: int host =GetHostId(); There is nothing more to it really, and never crashes for me. Oh and no surpise it crashed after 31, as that would be the maximum possible value. It wasn't making it even pass 10 on most runs. It was 1000 because I didn't know how far the random addition jumped and was brute forcing it. I know they start with 0 then do addition with a random integer. They also seem to do divide for a factor based on the total players which is why there was a sequence of 20s. Unless you use names and compare to blips I don't think there is a way to get players coordinates without brute forcing the pool with a loop and some check. I read somewhere blips where returning 0 on coordinates though. I think it was intentionally done like this in the sdk. Some people are using the functionality, but they're getting info off IRC where the devs hang out. It's not worth the time to find the algorithm in a debugger or script editor. It'll eventually be made public if R* doesn't fix their import table handling first and make it where inline patching would be mandatory. Edited June 30, 2009 by crackdawg Link to comment Share on other sites More sharing options...
sjaak327 Posted June 30, 2009 Share Posted June 30, 2009 Getting players coordinates is dead easy, as discussed before the playerid's on an MP game run from 0 to 31, to get player coords, use the playerindex to get the playerped, that will yield their coordinates. No need to use blips. Incidentially the blips coords problem has been fixed from hook 0.2.5 onwards, so these now also return correct coordinates. As said, I can get all names in MP without any crash, maybe your buffer isn't big enough, don't know what the maxium GFWL username lenght is tbh. note the usage of const char as opposed to a char buffer. Link to comment Share on other sites More sharing options...
aru Posted June 30, 2009 Share Posted June 30, 2009 if(GetPlayerName(playerIndex) != "**Invalid**") if that's intended to compare those two strings.. then you should be doing something like this: if( strcmp( GetPlayerName(playerIndex), "**Invalid**" ) == 0 ) or this: if( std::string(GetPlayerName(playerIndex)) != "**Invalid**" ) Also, only run your scan from 0 to 31... not any higher. There may not be any safeguards in the game regarding which player pool slot its accessing, and thus why its crashing. Might also help if you post a dump of the registers/stack/version # of GTAIV when the crash occurs if you can obtain that without XLive complaining too much. You can also do this and save yourself some itoa trouble: LogInfo("%s %u", GetPlayerName(playerIndex), (u32) playerIndex); Link to comment Share on other sites More sharing options...
crackdawg Posted June 30, 2009 Author Share Posted June 30, 2009 (edited) Thanks Aru. I found using blips saves a lot of trouble. I haven't tested how well they work as far as returning coordinates go yet, I'm about to go do it now. Here is what I cam up with for players. Not sure is the type cast will work: blip = GetFirstBlipInfoId(BLIP_PLAYER); while(DoesBlipExist(blip)) { GetBlipCoords(blip,&coords); LogInfo((char)coords); blip = GetNextBlipInfoId(BLIP_PLAYER); } Edited June 30, 2009 by crackdawg Link to comment Share on other sites More sharing options...
sjaak327 Posted June 30, 2009 Share Posted June 30, 2009 That's not going to work I bet, since blip coords are vector 3. something like: Vector3 coords; Getblipcoords(blip, &coords); LogInfo("X %G",coords.X); Link to comment Share on other sites More sharing options...
crackdawg Posted June 30, 2009 Author Share Posted June 30, 2009 (edited) That's not going to work I bet, since blip coords are vector 3. something like: Vector3 coords; Getblipcoords(blip, &coords); LogInfo("X %G",coords.X); Yeah I know, I put it to "Vector3",coords before I tested it ^^ and I got the Vector3 in the log...I think f32 will work on each vector. I actually got what I wanted, I'm sure this will make good reference to other people. Edited June 30, 2009 by crackdawg Link to comment Share on other sites More sharing options...
sjaak327 Posted June 30, 2009 Share Posted June 30, 2009 Well in any case, if all you want to do is get players coords, I would simply rely on playerid, primarily because it seems some people are able to remove their blip, hence you loose the ability to get their coords this way, simply using their playerid will be a sure way to get their coords, as I am pretty sure, there's no hiding the playerid. Link to comment Share on other sites More sharing options...
crackdawg Posted June 30, 2009 Author Share Posted June 30, 2009 Well in any case, if all you want to do is get players coords, I would simply rely on playerid, primarily because it seems some people are able to remove their blip, hence you loose the ability to get their coords this way, simply using their playerid will be a sure way to get their coords, as I am pretty sure, there's no hiding the playerid. Thanks. Also what's with things reoccurring from key state branches? I have my things set to F5-8 and I can execute something, and without pressing the buttons again the event reoccurs shortly after. I looked for something in the headers to reset a state or clear a keystate buffer but didn't see anything. It happens even with the most trivial code. I'm using if ((GetAsyncKeyState(VK_F5) & 1) != 0) for example in statedefault just like the sample. I'll tap F5 to execute a branch and shortly after it'll do it again without pressing anything. Link to comment Share on other sites More sharing options...
sjaak327 Posted June 30, 2009 Share Posted June 30, 2009 (edited) Well in any case, if all you want to do is get players coords, I would simply rely on playerid, primarily because it seems some people are able to remove their blip, hence you loose the ability to get their coords this way, simply using their playerid will be a sure way to get their coords, as I am pretty sure, there's no hiding the playerid. Thanks. Also what's with things reoccurring from key state branches? I have my things set to F5-8 and I can execute something, and without pressing the buttons again the event reoccurs shortly after. I looked for something in the headers to reset a state or clear a keystate buffer but didn't see anything. It happens even with the most trivial code. I'm using if ((GetAsyncKeyState(VK_F5) & 1) != 0) for example in statedefault just like the sample. I'll tap F5 to execute a branch and shortly after it'll do it again without pressing anything. Whatever you do don't use F8, I stopped using it shortly after patch 3 came out as it seems the any code that was assinged to that key would execute even if F8 wasn't pressed, not only with Aru's hook, also people using Alice reported the same problem, not sure if this is still an issue in patch 4 though, it might easily be. VK_F5 always works correctly for me, but I use something like : else if ((GetAsyncKeyState(MoneyKey1) & 1) != 0) where moneykey1 actually simply is VK_F5 read from an ini file, never had problems with using it like that (and I use a sh*t load of keys ) Only F8 is a problem since patch 3. Edited June 30, 2009 by sjaak327 Link to comment Share on other sites More sharing options...
crackdawg Posted June 30, 2009 Author Share Posted June 30, 2009 Well in any case, if all you want to do is get players coords, I would simply rely on playerid, primarily because it seems some people are able to remove their blip, hence you loose the ability to get their coords this way, simply using their playerid will be a sure way to get their coords, as I am pretty sure, there's no hiding the playerid. Thanks. Also what's with things reoccurring from key state branches? I have my things set to F5-8 and I can execute something, and without pressing the buttons again the event reoccurs shortly after. I looked for something in the headers to reset a state or clear a keystate buffer but didn't see anything. It happens even with the most trivial code. I'm using if ((GetAsyncKeyState(VK_F5) & 1) != 0) for example in statedefault just like the sample. I'll tap F5 to execute a branch and shortly after it'll do it again without pressing anything. Whatever you do don't use F8, I stopped using it shortly after patch 3 came out as it seems the any code that was assinged to that key would execute even if F8 wasn't pressed, not only with Aru's hook, also people using Alice reported the same problem, not sure if this is still an issue in patch 4 though, it might easily be. VK_F5 always works correctly for me, but I use something like : else if ((GetAsyncKeyState(MoneyKey1) & 1) != 0) where moneykey1 actually simply is VK_F5 read from an ini file, never had problems with using it like that (and I use a sh*t load of keys ) Only F8 is a problem since patch 3. Yeah it was F8 for me too. The rest are good. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now