Originally Posted by
Soularis
Keylogger eh?!?!?!
Holy christ. You're here now? Kindly get the **** out, as kynox has pointed out this section is over your head. This isn't the lulz-auto-it-macro-section, so what are you doing here?
Originally Posted by
Shynd
Now there's a good practice to get into. Who the **** comments code only because they're showing it to others.
I'm gonna admit that I usually only comment very obscure parts of my code, for example if there's a pointer offset I'm using that's not obvious I'll document where it came from, but if I can work it out in 5 seconds from just firing up IDA I probably won't bother.
That being said with the rewrite of all my code I'm doing now I'm taking the opportunity to do a full cleanup and proper commenting. When you're working at a low level on a really big project sometimes you just want to throw something in quickly to see if it works but not comment it incase it doesn't, then you never get around to cleaning it up and recommenting it. Prime example:
Code:
gpDumpLog->Add("enum eClientDB {");
unsigned int iDBCount = 0;
unsigned int dwRegisterDbcBase = 0;
unsigned int dwValue, dwRegDbcFunc, dwGetDbcFunc, dwDbcNameOff = 0;
std::string sFullDbcName, sDbcName;
do
{
if (!iDBCount)
dwRegisterDbcBase = __ClientDB__RegisterBase;
else
dwRegisterDbcBase += 0x14;
dwValue = *reinterpret_cast<unsigned int*>(dwRegisterDbcBase + 1);
dwRegDbcFunc = *reinterpret_cast<unsigned int*>(dwRegisterDbcBase + 0x10) + (dwRegisterDbcBase + 0x10) + 5 - 1;
dwGetDbcFunc = *reinterpret_cast<unsigned int*>(dwRegDbcFunc + 0x10) + (dwRegDbcFunc + 0x10) + 5 - 1;
dwDbcNameOff = *reinterpret_cast<unsigned int*>(dwGetDbcFunc + 1);
sFullDbcName = reinterpret_cast<const char*>(dwDbcNameOff);
sDbcName = sFullDbcName;
sDbcName.erase(0,14);
sDbcName.erase(sDbcName.end() - 4, sDbcName.end());
sDbcName.insert(0,"tDB_");
char TempValue[10] = { 0 };
sprintf_s(TempValue,sizeof(TempValue),"0x%X",dwValue);
sDbcName.append(" = ");
sDbcName.append(TempValue);
sDbcName.append(", // ");
char TempPointer[12] = { 0 };
sprintf_s(TempPointer,sizeof(TempPointer),"0x00%X",reinterpret_cast<unsigned int>(gpClientDB->GetMap()[dwValue]));
sDbcName.append(TempPointer);
gpDumpLog->Add(sDbcName.c_str());
++iDBCount;
} while (*reinterpret_cast<unsigned char*>(dwRegisterDbcBase + 0x14) == 0x68);
dwRegisterDbcBase = __DBClient__RegVideoHardware;
dwValue = *reinterpret_cast<unsigned int*>(dwRegisterDbcBase + 1);
dwRegDbcFunc = *reinterpret_cast<unsigned int*>(dwRegisterDbcBase + 0x10) + (dwRegisterDbcBase + 0x10) + 5 - 1;
dwGetDbcFunc = *reinterpret_cast<unsigned int*>(dwRegDbcFunc + 0x10) + (dwRegDbcFunc + 0x10) + 5 - 1;
dwDbcNameOff = *reinterpret_cast<unsigned int*>(dwGetDbcFunc + 1);
sFullDbcName = reinterpret_cast<const char*>(dwDbcNameOff);
sDbcName = sFullDbcName;
sDbcName.erase(0,14);
sDbcName.erase(sDbcName.end() - 4, sDbcName.end());
sDbcName.insert(0,"tDB_");
char TempValue1[10] = { 0 };
sprintf_s(TempValue1,sizeof(TempValue1),"0x%X",dwValue);
sDbcName.append(" = ");
sDbcName.append(TempValue1);
sDbcName.append(",");
gpDumpLog->Add(sDbcName.c_str());
++iDBCount;
dwRegisterDbcBase = __DBClient__RegStartupStrings;
dwValue = *reinterpret_cast<unsigned int*>(dwRegisterDbcBase + 1);
dwRegDbcFunc = *reinterpret_cast<unsigned int*>(dwRegisterDbcBase + 0x10) + (dwRegisterDbcBase + 0x10) + 5 - 1;
dwGetDbcFunc = *reinterpret_cast<unsigned int*>(dwRegDbcFunc + 0x10) + (dwRegDbcFunc + 0x10) + 5 - 1;
dwDbcNameOff = *reinterpret_cast<unsigned int*>(dwGetDbcFunc + 1);
sFullDbcName = reinterpret_cast<const char*>(dwDbcNameOff);
sDbcName = sFullDbcName;
sDbcName.erase(0,14);
sDbcName.erase(sDbcName.end() - 4, sDbcName.end());
sDbcName.insert(0,"tDB_");
char TempValue2[10] = { 0 };
sprintf_s(TempValue2,sizeof(TempValue2),"0x%X",dwValue);
sDbcName.append(" = ");
sDbcName.append(TempValue2);
sDbcName.append(",");
gpDumpLog->Add(sDbcName.c_str());
++iDBCount;
gpDumpLog->Add("ntDB_COUNT = 0x%X", iDBCount );
gpDumpLog->Add("};n");
PS. inb4 "holy shit what does that do!"
Originally Posted by
Shynd
And if you were to take a sabbatical from WoW for a few months and then come back to it you'd still be able to read your code line by line because you'd still have every little thing memorized? Give me a break. Only shitty programmers don't comment their code, at least parts of it.
That may be partly true but there's a difference between good and bad commenting. If you comment every single line like you suffer from OCD that's not really a good idea because it reduces readability. Furthermore, you shouldn't be commenting WHAT lines do (because any programmer reading your code should be able to figure that out, unless it is particularly obscure), but WHY. Also, I dunno what your code looks like but you can avoid the need for comments altogether sometimes if you don't use magic numbers and name everything properly and sensibly.
eg The function above which isn't in one of the code files I have rewritten yet COULD be rewritten to look nice and not have to be commented at all. Examples of how to do this would be:
* Convert magic numbers into const ints or enums
* Move obscure functionality into seperate functions (ie the resolving of relative jumps)
* Move string functionality into better named functions
* etc.
That function is a particularly difficult chunk of code to understand so it would probably still benifit from comments, but my point is while they are nice they're not always necessary. You should comment your code for other programmers to read, not for your mum to read, or at least that's my opinion.