Skip to content

Commit

Permalink
changed some output
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluscream committed May 6, 2016
1 parent 95ee6ff commit a137058
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ Steam Name Changer.VC.VC.opendb
Steam Name Changer.VC.db
*.tlog
STEAMAPI_INTERFACE/Release/*
Release/*
Release/*
.vs/Steam Name Changer/v14/.suo
Binary file modified .vs/Steam Name Changer/v14/.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion Release/steam_appid.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
380080
10
Binary file modified Steam Name Changer.VC.db
Binary file not shown.
10 changes: 5 additions & 5 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ int main(int argc, char* argv[])

//Format application path
if (!SetAppPath(g_szAppPath)) {
ConsolePrint("[SetAppPath] failed: %d", GetLastError());
ConsolePrint("[Formatting App Path] Failed: %d", GetLastError());
return EXIT_FAILURE;
}

//Register console control handler
if (!SetConsoleCtrlHandler(&ConsoleControlHandler, TRUE)) {
ConsolePrint("[SetConsoleCtrlHandler] failed: %d", GetLastError());
ConsolePrint("[Console Control Handler] Failed to register: %d", GetLastError());
return EXIT_FAILURE;
}

//Initialize Steam API

InitResult irResult = g_oSteamAPI.Initialize(g_szAppPath);

ConsolePrint("[g_oSteamAPI.Initialize] result: %d (%s) -> %d\n", irResult, g_oSteamAPI.InitResultToString(irResult), GetLastError());
ConsolePrint("[SteamAPI] Initialized: %d (%s) -> %d\n", irResult, g_oSteamAPI.InitResultToString(irResult), GetLastError());

if (irResult != IR_SUCCESS)
return EXIT_FAILURE;
Expand All @@ -83,14 +83,14 @@ int main(int argc, char* argv[])

ISteamFriends* pSteamFriends = g_oSteamAPI.SteamFriendsInterface();
if (!pSteamFriends)
ConsolePrint("[g_oSteamAPI.SteamFriendsInterface] failed");
ConsolePrint("[SteamAPI] SteamFriendsInterface failed to initialize!");

g_oNameChanger.SetInterface(pSteamFriends);
g_oNameChanger.SetStatus(TRUE);

//Main loop

ConsolePrint("Entering main loop, press ESC to exit.");
ConsolePrint("Waiting for games, press [ESC] to exit.");

g_oNameChanger.ReadNames();

Expand Down
50 changes: 30 additions & 20 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace std;
*/

//======================================================================
BOOL SetAppPath(LPSTR lpszOut)
bool SetAppPath(char * lpszOut)
{
//Write application path to string

Expand All @@ -38,7 +38,7 @@ BOOL SetAppPath(LPSTR lpszOut)
//======================================================================

//======================================================================
VOID ConsolePrint(LPCSTR lpszFmt, ...)
void ConsolePrint(char* lpszFmt, ...)
{
//Print text to console

Expand All @@ -56,14 +56,14 @@ VOID ConsolePrint(LPCSTR lpszFmt, ...)
//======================================================================

//======================================================================
VOID CNameChanger::SetInterface(ISteamFriends* pSteamFriends)
void CNameChanger::SetInterface(ISteamFriends* pSteamFriends)
{
//Set pointer to Steam Friends interface

this->pSteamFriends = pSteamFriends;
}
//======================================================================
VOID CNameChanger::ReadConfig()
void CNameChanger::ReadConfig()
{

}
Expand Down Expand Up @@ -106,7 +106,7 @@ void convertToLower(char *str)

//======================================================================

VOID CNameChanger::ReadNames()
void CNameChanger::ReadNames()
{
FILE *fp = fopen("names.cfg", "rb");
int len = get_file_size(fp);
Expand Down Expand Up @@ -135,7 +135,7 @@ VOID CNameChanger::ReadNames()
//======================================================================

//======================================================================
BOOL CNameChanger::SetStatus(BOOL bEnable)
bool CNameChanger::SetStatus(bool bEnable)
{
//Set name change status

Expand All @@ -158,7 +158,7 @@ BOOL CNameChanger::SetStatus(BOOL bEnable)

//======================================================================

LPSTR CNameChanger::GetName(LPSTR game)
char *CNameChanger::GetName(char * game)
{
if (!strcmp(game, "<unknown>"))
return NULL;
Expand All @@ -176,7 +176,7 @@ LPSTR CNameChanger::GetName(LPSTR game)

//======================================================================

BOOL CNameChanger::IsProcessListed(LPSTR game)
bool CNameChanger::IsProcessListed(char * game)
{
for (auto process : namecombinations)
{
Expand All @@ -190,7 +190,7 @@ BOOL CNameChanger::IsProcessListed(LPSTR game)
//======================================================================

//======================================================================
LPSTR CNameChanger::GetCurrentName()
char *CNameChanger::GetCurrentName()
{
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
Expand Down Expand Up @@ -231,12 +231,16 @@ LPSTR CNameChanger::GetCurrentName()
}
}

if (IsProcessListed(szProcessName))
if (IsProcessListed(szProcessName)) {
if(strcmp(szProcessName, lastGame)){
printf("Found running game: %s\n", szProcessName);
lastGame = strdup(szProcessName);
}

return GetName(szProcessName);
}
}
catch (int e)
{
}
catch (int e){}

}

Expand All @@ -245,12 +249,10 @@ LPSTR CNameChanger::GetCurrentName()
//======================================================================

//======================================================================
VOID CNameChanger::Think(VOID)
void CNameChanger::Think()
{
//Process name change

#define NC_TIMETOWAIT 1000

if (!bStatus)
return;

Expand All @@ -262,17 +264,25 @@ VOID CNameChanger::Think(VOID)
dwLastTimer = GetTickCount();

//Change name
LPSTR pString = GetCurrentName();
char *pString = GetCurrentName();
char *pCurName = strdup(pSteamFriends->GetPersonaName());

if (pString) {
static bool isFirstTime = true;

if (oldName != NULL && !strcmp(oldName, pString))
return;

// Set the old name
oldName = strdup(pString);

// Set the actual name
printf("Setting personal name to %s.\n", pString);
pSteamFriends->SetPersonaName(pString);
if (!isFirstTime)
{
ConsolePrint("Changing Steam name from %s to %s.\n", oldName, pString);
pSteamFriends->SetPersonaName(pString);
}

isFirstTime = false;
}
}
}
Expand Down
23 changes: 12 additions & 11 deletions utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
*/

//======================================================================
BOOL SetAppPath(LPSTR lpszOut);
VOID ConsolePrint(LPCSTR lpszFmt, ...);
bool SetAppPath(char * lpszOut);
void ConsolePrint(char * lpszFmt, ...);
//======================================================================

//======================================================================
class CNameChanger { //Changes the Steam Friends name each defined msecs permanently
private:
BOOL bStatus;
bool bStatus;

DWORD dwCurTimer;
DWORD dwLastTimer;
Expand All @@ -30,22 +30,23 @@ class CNameChanger { //Changes the Steam Friends name each defined msecs permane

ISteamFriends *pSteamFriends;

LPSTR GetCurrentName();
LPSTR GetName(LPSTR game);
BOOL IsProcessListed(LPSTR game);
char * GetCurrentName();
char * GetName(char * game);
bool IsProcessListed(char * game);

LPSTR oldName = NULL;
char * oldName = NULL;
char * lastGame = "";

std::vector<std::pair<std::string, std::string>> namecombinations;

public:
CNameChanger() { bStatus = FALSE; pSteamFriends = NULL; }
~CNameChanger() { }

VOID SetInterface(ISteamFriends* pSteamFriends);
VOID ReadConfig();
VOID ReadNames();
BOOL SetStatus(BOOL bEnable);
void SetInterface(ISteamFriends* pSteamFriends);
void ReadConfig();
void ReadNames();
bool SetStatus(bool bEnable);


VOID Think(VOID);
Expand Down
4 changes: 3 additions & 1 deletion vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#define PROGRAM_CONTACT "[email protected]"
#define PROGRAM_INFO PROGRAM_NAME " version " PROGRAM_VERSON " developed by " PROGRAM_AUTHOR " (" PROGRAM_CONTACT ")"
//======================================================================

#define ENABLED 1
#define METHOD "GAME"
#define NC_TIMETOWAIT 1000
//======================================================================
extern char g_szAppPath[MAX_PATH];
extern CAccessSteamAPI g_oSteamAPI;
Expand Down

0 comments on commit a137058

Please sign in to comment.