MQ2Screenshot v1.02 Wiki Link
Turns off mq2 captions, takes screenshot, then turns captions back on.
Typing /screenshot or /ss will initiate a screenshot without MQ items in the picture.
Usage: /ss [help | load | save | delay | acmdadd | acmddel | bcmdadd | bcmddel | cmdlist | cmdclear]
help = Display all the commands available with a description.
load = Load all commands from the .ini file.
save = Saves all commands to the .ini file.
delay = How long to wait for MQCaptions to turn off. (Pulses)
acmdadd = Adds a command that is executed after the screenshot is taken
acmddel = Deletes a command that is executed after the screenshot is taken.
bcmdadd = Adds a command that is executed before the screenshot is taken.
bcmddel = Deletes a command that is executed before the screenshot is taken.
cmdlist = Lists all before and after commands.
cmdclear = Clears all before and after commands.
ex.
Before commands
/ss bcmdadd "/keypress NETSTAT"
/ss bcmdadd "/plugin mq2chatwnd unload"
/ss bcmdadd "/keypress FULLSCREEN"
After commands
/ss acmdadd "/keypress NETSTAT"
/ss acmdadd "/plugin mq2chatwnd"
/ss acmdadd "/keypress FULLSCREEN"
Turns off mq2 captions, takes screenshot, then turns captions back on.
Typing /screenshot or /ss will initiate a screenshot without MQ items in the picture.
Usage: /ss [help | load | save | delay | acmdadd | acmddel | bcmdadd | bcmddel | cmdlist | cmdclear]
help = Display all the commands available with a description.
load = Load all commands from the .ini file.
save = Saves all commands to the .ini file.
delay = How long to wait for MQCaptions to turn off. (Pulses)
acmdadd = Adds a command that is executed after the screenshot is taken
acmddel = Deletes a command that is executed after the screenshot is taken.
bcmdadd = Adds a command that is executed before the screenshot is taken.
bcmddel = Deletes a command that is executed before the screenshot is taken.
cmdlist = Lists all before and after commands.
cmdclear = Clears all before and after commands.
ex.
Before commands
/ss bcmdadd "/keypress NETSTAT"
/ss bcmdadd "/plugin mq2chatwnd unload"
/ss bcmdadd "/keypress FULLSCREEN"
After commands
/ss acmdadd "/keypress NETSTAT"
/ss acmdadd "/plugin mq2chatwnd"
/ss acmdadd "/keypress FULLSCREEN"
Code:
//Plugin by Unity0110
#include "../MQ2Plugin.h"
#include <vector>
PreSetup("MQ2Screenshot");
PLUGIN_VERSION(1.02);
// Global variables
bool bScreenshot = false;
bool bEnableDelay = false;
int Counter;
int ssDelay;
int ssDelayDefault = 50;
PSPAWNINFO pChar = GetCharInfo()->pSpawn;
vector<string> ScreenshotBeforeCMD;
vector<string> ScreenshotAfterCMD;
VOID LoadINI(VOID)
{
int KeyIndex;
char KeyName[MAX_STRING], KeyValue[MAX_STRING];
// Set delay
ssDelay = GetPrivateProfileInt("Settings", "Delay", ssDelayDefault, INIFileName);
if (ssDelay<5) ssDelay = ssDelayDefault;
// Load before commands
ScreenshotBeforeCMD.clear();
KeyIndex = 1;
do {
sprintf(KeyName, "bcmd%d", KeyIndex);
GetPrivateProfileString("Before commands", KeyName, NULL, KeyValue, MAX_STRING, INIFileName);
if(strlen(KeyValue)>0) {
strlwr(KeyValue);
ScreenshotBeforeCMD.push_back(KeyValue);
}
KeyIndex++;
} while(strlen(KeyValue)>0);
// Load after commands
ScreenshotAfterCMD.clear();
KeyIndex = 1;
do {
sprintf(KeyName, "acmd%d", KeyIndex);
GetPrivateProfileString("After commands", KeyName, NULL, KeyValue, MAX_STRING, INIFileName);
if(strlen(KeyValue)>0) {
strlwr(KeyValue);
ScreenshotAfterCMD.push_back(KeyValue);
}
KeyIndex++;
} while(strlen(KeyValue)>0);
WriteChatf("\ayMQ2Screenshot\ax by \arUnity0110\ax");
WriteChatf("\arBefore\ax Commands loaded: \ay%i\ax. \agAfter\ax Commands loaded: \ay%i\ax.", ScreenshotBeforeCMD.size(), ScreenshotAfterCMD.size());
}
VOID SaveINI(VOID)
{
char KeyName[MAX_STRING];
char szTemp[MAX_STRING];
// Save Delay value
sprintf(szTemp, "%i", ssDelay);
WritePrivateProfileString("Settings","Delay",szTemp,INIFileName);
// Save before commands
WritePrivateProfileSection("Before Commands", "", INIFileName);
for (register unsigned int Index = 0; Index < ScreenshotBeforeCMD.size(); Index++) {
string& VectorRef = ScreenshotBeforeCMD[Index];
sprintf(KeyName, "bcmd%d", Index+1);
WritePrivateProfileString("Before Commands",KeyName,VectorRef.c_str(),INIFileName);
}
// Save after commands
WritePrivateProfileSection("After Commands", "", INIFileName);
for (register unsigned int Index = 0; Index < ScreenshotAfterCMD.size(); Index++) {
string& VectorRef = ScreenshotAfterCMD[Index];
sprintf(KeyName, "acmd%d", Index+1);
WritePrivateProfileString("After Commands",KeyName,VectorRef.c_str(),INIFileName);
}
WriteChatf("\ayMQ2Screenshot\ax \arbefore\ax and \agafter\ax commands saved to .ini!");
}
VOID showHelp(VOID)
{
// Display help
WriteChatf("\atUsage\ax\ay:\ax \ar/\ax\ayss\ax \ar[\ax\athelp\ax \ag|\ax \atload\ax \ag|\ax \atsave\ax \ag|\ax \atdelay\ax \ag|\ax \atacmdadd\ax \ag|\ax \atacmddel\ax \ag|\ax \atbcmdadd\ax \ag|\ax \atbcmddel\ax \ag|\ax \atcmdlist\ax \ag|\ax \atcmdclear\ax\ar]\ax");
WriteChatf("\athelp\ax \ay=\ax \agDisplay all the commands available with a description.\ax");
WriteChatf("\atload\ax \ay=\ax \agLoad all commands from the .ini file.\ax");
WriteChatf("\atsave\ax \ay=\ax \agSaves all commands to the .ini file.\ax");
WriteChatf("\atdelay\ax \ay=\ax \agHow long to wait for MQCaptions to turn off. (Pulses)\ax");
WriteChatf("\atacmdadd\ax \ay=\ax \agAdds a command that is executed after the screenshot is taken.\ax");
WriteChatf("\atacmddel\ax \ay=\ax \agDeletes a command that is executed after the screenshot is taken.\ax");
WriteChatf("\atbcmdadd\ax \ay=\ax \agAdds a command that is executed before the screenshot is taken.\ax");
WriteChatf("\atbcmddel\ax \ay=\ax \agDeletes a command that is executed before the screenshot is taken.\ax");
WriteChatf("\atcmdlist\ax \ay=\ax \agLists all before and after commands.\ax");
WriteChatf("\atcmdclear\ax \ay=\ax \agClears all before and after commands.\ax");
}
VOID beforeCommands(VOID)
{
// Execute before commands
for (register unsigned int Index = 0; Index < ScreenshotBeforeCMD.size(); Index++)
{
string& VectorRef = ScreenshotBeforeCMD[Index];
DoCommand(pChar, (PCHAR)VectorRef.c_str());
}
DoCommand(pChar,"/caption MQCaptions off");
bScreenshot = true;
}
VOID afterCommands(VOID)
{
// Execute after commands
for (register unsigned int Index = 0; Index < ScreenshotAfterCMD.size(); Index++)
{
string& VectorRef = ScreenshotAfterCMD[Index];
DoCommand(pChar, (PCHAR)VectorRef.c_str());
}
DoCommand(pChar,"/caption MQCaptions on");
}
PLUGIN_API VOID OnPulse(VOID)
{
if (bEnableDelay)
{
Counter++;
if (Counter < ssDelay) return;
Counter = 0;
bEnableDelay = false;
DoCommand(pChar,"/keypress SCREENCAP");
afterCommands();
}
}
VOID ScreenshotCommand(PSPAWNINFO pChar, PCHAR szLine)
{
char szTemp[MAX_STRING], szBuffer[MAX_STRING];
GetArg(szTemp, szLine, 1);
// Display help commands
if (!stricmp(szTemp, "help")) {
showHelp();
}
// Reload .ini
else if (!stricmp(szTemp, "load")) {
LoadINI();
}
// Save current settings & names
else if (!stricmp(szTemp, "save")) {
SaveINI();
}
// Set delay
else if (!stricmp(szTemp, "delay")) {
GetArg(szBuffer, szLine, 2);
ssDelay = atoi(szBuffer);
if(ssDelay>0) {
WriteChatf("\ayMQ2Screenshot\ax: Delay set to \ay%i\ax", ssDelay);
} else {
ssDelay = ssDelayDefault;
WriteChatf("\ayMQ2Screenshot\ax: Delay set to default (\ay%i\ax).", ssDelayDefault);
}
}
// Add Before command
else if (!stricmp(szTemp, "bcmdadd")) {
GetArg(szBuffer, szLine, 2);
if(strlen(szBuffer)>0) {
ScreenshotBeforeCMD.push_back(szBuffer);
WriteChatf("\ayMQ2Screenshot\ax: Before command \ay'%s'\ax added.", szBuffer);
}
else
WriteChatf("\ayMQ2Screenshot\ax: Command to add not specified.");
}
// Add After command
else if (!stricmp(szTemp, "acmdadd")) {
GetArg(szBuffer, szLine, 2);
if(strlen(szBuffer)>0) {
ScreenshotAfterCMD.push_back(szBuffer);
WriteChatf("\ayMQ2Screenshot\ax: After command \ay'%s'\ax added.", szBuffer);
}
else
WriteChatf("\ayMQ2Screenshot\ax: Command to add not specified.");
}
// Delete Before command #
else if (!stricmp(szTemp, "bcmddel")) {
GetArg(szBuffer, szLine, 2);
unsigned int Index = atoi(szBuffer);
if(Index > 0 && Index < ScreenshotBeforeCMD.size()+1) {
string& VectorRef = ScreenshotBeforeCMD[Index-1];
WriteChatf("\ayMQ2Screenshot\ax: Command %d '\ay%s\ax' deleted.", Index, VectorRef.c_str());
ScreenshotBeforeCMD.erase(ScreenshotBeforeCMD.begin() + (Index-1));
}
else
WriteChatf("\ayMQ2Screenshot\ax: Command \ay%d\ax does not exist.", Index);
}
// Delete After command #
else if (!stricmp(szTemp, "acmddel")) {
GetArg(szBuffer, szLine, 2);
unsigned int Index = atoi(szBuffer);
if(Index > 0 && Index < ScreenshotAfterCMD.size()+1) {
string& VectorRef = ScreenshotAfterCMD[Index-1];
WriteChatf("\ayMQ2Screenshot\ax: Command %d '\ay%s\ax' deleted.", Index, VectorRef.c_str());
ScreenshotAfterCMD.erase(ScreenshotAfterCMD.begin() + (Index-1));
}
else
WriteChatf("\ayMQ2Screenshot\ax: Command \ay%d\ax does not exist.", Index);
}
// Clear all commands
else if (!stricmp(szTemp, "cmdclear")) {
ScreenshotBeforeCMD.clear();
ScreenshotAfterCMD.clear();
WriteChatf("\ayMQ2Screenshot\ax: Before and After Commands cleared.");
}
// List all commands
else if (!stricmp(szTemp, "cmdlist")) {
WriteChatf("\arBefore\ax Commands loaded: \ay%i\ax. \agAfter\ax Commands loaded: \ay%i\ax.", ScreenshotBeforeCMD.size(), ScreenshotAfterCMD.size());
// Before commands
if (ScreenshotBeforeCMD.size()>0) {
WriteChatf("\ayMQ2Screenshot\ax: \arBefore\ax Commands.");
for (register unsigned int Index = 0; Index < ScreenshotBeforeCMD.size(); Index++) {
string& VectorRef = ScreenshotBeforeCMD[Index];
WriteChatf("%d: %s", Index+1, VectorRef.c_str());
}
}
if (ScreenshotAfterCMD.size()>0) {
// After commands
WriteChatf("\ayMQ2Screenshot\ax: \agAfter\ax Commands.");
for (register unsigned int Index = 0; Index < ScreenshotAfterCMD.size(); Index++) {
string& VectorRef = ScreenshotAfterCMD[Index];
WriteChatf("%d: %s", Index+1, VectorRef.c_str());
}
}
}
// No parameter is take Screenshot
else if(!strlen(szTemp)) {
beforeCommands();
}
// Otherwise, show help
else {
showHelp();
}
}
int FindS(string strMain, string strWord)
{
int pos;
if (strMain.find(strWord) == 'npos') {
return -1;
} else {
pos = strMain.find(strWord);
return pos;
}
}
PLUGIN_API DWORD OnWriteChatColor(PCHAR Line, DWORD Color, DWORD Filter)
{
if (FindS(Line, "MQCaptions are now yOffx.")==0)
{
if (bScreenshot)
{
bScreenshot = false;
bEnableDelay = true;
}
}
return 0;
}
PLUGIN_API VOID InitializePlugin(VOID)
{
DebugSpewAlways("Initializing MQ2Screenshot");
LoadINI();
AddCommand("/screenshot", ScreenshotCommand);
AddCommand("/ss", ScreenshotCommand);
}
PLUGIN_API VOID ShutdownPlugin(VOID)
{
DebugSpewAlways("Shutting down MQ2Screenshot");
RemoveCommand("/screenshot");
RemoveCommand("/ss");
}