예제 #1
0
void CAutoConnector::FailedToConnectBecauseNoWindowInList()
{
	p_sharedmem->RememberTimeOfLastFailedAttemptToConnect();

	int cySize = GetSystemMetrics(SM_CYSIZE);
	int cyMenuSize = GetSystemMetrics(SM_CYMENU);

	if (preferences.autoconnector_when_to_connect() == k_AutoConnector_Connect_Once)
	{
		if (cySize != 18 || cyMenuSize != 19)
		{
			OH_MessageBox_Error_Warning(
				"Cannot find table.\n\n"
				"It appears that your settings are not configured according to OpenHoldem specifications.\n"
				"You must ensure that XP themes are not used (Use Windows Classic style) and\n"
				"font size is set to normal.\n\n"
				"For more info, read the manual and visit the user forums.", 
				"Cannot find table");
		}
		else
		{
			OH_MessageBox_Error_Warning(
				"No valid tables found\n\n"
				"There seems to be no unserved table open\n"
				"or your table does not match the size and titlestring\n"
				"defined in your tablemaps.\n"
				"For more info, read the manual and visit the user forums.",
				"Cannot find table");
		}
	}
	GoIntoPopupBlockingMode();
}
예제 #2
0
void CAutoConnector::LoadScraperDLL()
{
	// scraper.dll - failure in load is NOT fatal
	theApp.UnloadScraperDLL();
	CString filename = p_tablemap->scraperdll();
	if (filename.IsEmpty()) 
	{
		return;
	}
	// Otherwise: try to load DLL
	p_filenames->SwitchToOpenHoldemDirectory();
	theApp._scraper_dll = LoadLibrary(filename);

	if (theApp._scraper_dll == NULL)
	{
		CString	error_message = "";
		error_message.Format("Unable to load scraper-dll: \"%s\"\n\n"
			"Error-code: %d", filename, GetLastError());
		OH_MessageBox_Error_Warning(error_message);
		return;
	}

	theApp._dll_scraper_process_message = (scraper_process_message_t) GetProcAddress(theApp._scraper_dll, "ProcessMessage");
	theApp._dll_scraper_override = (scraper_override_t) GetProcAddress(theApp._scraper_dll, "OverrideScraper");

	if (theApp._dll_scraper_process_message==NULL || theApp._dll_scraper_override==NULL)
	{
		OH_MessageBox_Error_Warning("Unable to find all symbols in scraper.dll");
		theApp.UnloadScraperDLL();
	}
	else
	{
			write_log(preferences.debug_autoconnector(), "[CAutoConnector] scraper.dll (%s) loaded, ProcessMessage and OverrideScraper found.\n", filename);
	}
}
예제 #3
0
CSessionCounter::CSessionCounter()
{	
	_session_id = -1;

	// Try to get a _session_id that is not in use.
	for (int i=0; i<MAX_SESSION_IDS; i++)
	{
		// Name the mutexes A..Y
		CString mutex_name = preferences.mutex_name() + "_" + CString(char('A' + i));
		hMutex = CreateMutex(0, FALSE, mutex_name);
		if (GetLastError() != ERROR_ALREADY_EXISTS)
		{
			_session_id = i;
			return;
		}
		else
		{
			CloseHandle(hMutex);
		}
	}

	// Otherwise: We failed. No ID available.
	OH_MessageBox_Error_Warning("Could not grab a session ID.\n"
		"Too many instances of OpenHoldem\n",
		"SessionCounter Error");

	PostQuitMessage(-1);
}
void CConfigurationCheck::CheckForSwapMouseBtns()
{
	CString p_szKeySwapBtns = "Control Panel\\Mouse\\";
	CString p_szNameSwapBtns = "SwapMouseButtons";

	bool SwapBtns = false;

	if (atoi(GetValue("HKCU", 1, p_szKeySwapBtns, p_szNameSwapBtns)) == 1)
	{
		SwapBtns = true;
	}

	if (SwapBtns == true)
	{
		OH_MessageBox_Error_Warning("It appears that your Mouse settings are not configured according to OpenHoldem specifications.\n\n"
			
			"The autoplayer has to generate mouse-events via a very low-level system-interface,\n"
			"and windows might/will swap these hardware-events for their inverse logical responses.\n\n"
			"This means Casinos clients will no longer interpret mouse-events correctly !\n"
			"Please Disable the - Swap Mouse Buttons - option in :\n\n"
			"Control Panel-> Mouse.\n\n"
			"and restart your user session in order to proceed\n",
			"Caution: Swap Mouse Buttons Activated");
	}
}
예제 #5
0
void CSymbolEngineLists::ErrorListNumberOutOfRange(int list)
{
    CString message;
    message.Format("List out of range.\n"
                   "%i should be in the range [0..999]", list);
    OH_MessageBox_Error_Warning(message, "ERROR");
}
예제 #6
0
void CFormulaParser::ParseOpenPPLLibraryIfNeeded() {
  assert(p_function_collection != NULL);
  if (p_function_collection->OpenPPLLibraryCorrectlyParsed()) {
    write_log(preferences.debug_parser(), 
	    "[FormulaParser] OpenPPL-library already correctly loaded. Nothing to do.\n");
    return;
  }
  assert(p_filenames != NULL);
  CString openPPL_path = p_filenames->OpenPPLLibraryPath();
  if (_access(openPPL_path, F_OK) != 0) {
    // Using a message-box instead of silent logging, as OpenPPL is mandatory 
    // and we expect the user to supervise at least the first test.
    CString message;
    message.Format("Can not load \"%s\".\nFile not found.\n", openPPL_path);
    OH_MessageBox_Error_Warning(message);
    p_function_collection->SetOpenPPLLibraryLoadingState(false);
    return;
  }
  CFile openPPL_file(openPPL_path, 
    CFile::modeRead | CFile::shareDenyWrite);
  write_log(preferences.debug_parser(), 
	    "[FormulaParser] Going to load and parse OpenPPL-library\n");
  CArchive openPPL_archive(&openPPL_file, CArchive::load); 
  ParseFile(openPPL_archive);
  p_function_collection->SetOpenPPLLibraryLoadingState(CParseErrors::AnyError() == false);
}
예제 #7
0
void CRebuyManagement::ExecuteRebuyScript()
{
	// Call the external rebuy script.
	//
	// CAUTION! DO NOT USE THIS FUNCTION DIRECTLY!
	// It has to be protected by a mutex.
	// We assume, the autoplayer does that.
	//
	// Build command-line-options for rebuy-script
	write_log(preferences.debug_rebuy(), "[CRebuyManagement] ExecuteRebuyScript");
	CString Casino;
	if (p_tablemap->s$()->find("sitename") != p_tablemap->s$()->end())
	{
		Casino = p_tablemap->s$()->find("sitename")->second.text.GetString();
	}
	else
	{
		Casino = "Undefined";
	}
	HWND WindowHandleOfThePokerTable = p_autoconnector->attached_hwnd();
	double SmallBlind = p_symbol_engine_tablelimits->sblind();
	double BigBlind = p_symbol_engine_tablelimits->bblind();
	double BigBet = p_symbol_engine_tablelimits->bigbet();
	int UserChair = p_symbol_engine_userchair->userchair();
	double Balance = p_symbol_engine_chip_amounts->balance(UserChair);
	double TargetAmount = p_autoplayer_functions->f$rebuy();
	CString RebuyScript = preferences.rebuy_script();
	CString CommandLine;
	CommandLine.Format(CString("%s %s %u %f %f %f %f %f %f"), 
		RebuyScript, Casino, WindowHandleOfThePokerTable, 
		UserChair, Balance, SmallBlind, BigBlind, BigBet, TargetAmount);
	// For some docu on "CreateProcess" see:
	// http://pheatt.emporia.edu/courses/2005/cs260s05/hand39/hand39.htm
	// http://msdn.microsoft.com/en-us/library/aa908775.aspx
	// http://www.codeproject.com/KB/threads/CreateProcessEx.aspx
	STARTUPINFO StartupInfo;
    PROCESS_INFORMATION ProcessInfo; 
	memset(&StartupInfo, 0, sizeof(StartupInfo));
	memset(&ProcessInfo, 0, sizeof(ProcessInfo));
	StartupInfo.cb = sizeof(StartupInfo); 
	write_log(preferences.debug_rebuy(), "[CRebuyManagement] command line: %s\n", CommandLine);
	if(CreateProcess(NULL, CommandLine.GetBuffer(), NULL, 
		false, 0, NULL, NULL, 0, &StartupInfo, &ProcessInfo))
	{
		// Docu for WaitForSingleObject:
		// http://msdn.microsoft.com/en-us/library/ms687032(VS.85).aspx
		// It seems, none of the exitcodes is relevant for us.
		//
		// Wait for termination of the rebuy-script, if necessary forever,
		// as we can't release the (autoplayer)mutex as long as the script is running.
		int ExitCode = WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
	}
	else
	{
		CString ErrorMessage = CString("Could not execute rebuy-script: ") + CString(RebuyScript) + "\n";
		write_log(preferences.debug_rebuy(), ErrorMessage.GetBuffer());
		OH_MessageBox_Error_Warning(ErrorMessage.GetBuffer(), "Error");
	}
}
void CSelftestParserEvaluator::Test() {
  if (!p_function_collection->Exists(kSelftestName)) {
    OH_MessageBox_Error_Warning("Can't find selftest-function\n"
      "Please get in contact with the developmen team.\n");
    return;
  }
  double result = p_function_collection->Evaluate(kSelftestName);
  if (result != kSelftestExpectedResult) {
    CString message;
    message.Format("Selftest failed.\n"
      "Please get in contact with the developmen team.\n"
      "Calculated result = %.3f\n"
      "Expected result = %.3f\n",
      result, kSelftestExpectedResult);
    OH_MessageBox_Error_Warning(message);
  }
}
void CConfigurationCheck::CheckForFontSmoothing()
{
	CString p_szKeyFontSmoothing = "Control Panel\\Desktop\\";
	CString p_szNameFontSmooth = "FontSmoothing";
	CString p_szNameFontSmoothType = "FontSmoothingType";

	bool font_smoothing = true;

	if (atoi(GetValue("HKCU", 1, p_szKeyFontSmoothing, p_szNameFontSmooth)) == 0)
	{
		if (atoi(GetValue("HKCU", 0, p_szKeyFontSmoothing, p_szNameFontSmoothType)) == 0)
		{
			font_smoothing = false;
		}
	}

	if (font_smoothing == true)
	{
		if (atoi(GetValue("HKCU", 1, p_szKeyFontSmoothing, p_szNameFontSmooth)) == 2)
		{
			int FontSmoothType = atoi(GetValue("HKCU", 0, p_szKeyFontSmoothing, p_szNameFontSmoothType));

			if (FontSmoothType == 2)
			{
				OH_MessageBox_Error_Warning("It appears that Cleartype font smoothing is enabled.\n"
							"\n"
							"In order for OpenHoldem to reliably\n"
							"extract information from the poker client\n"
							"you should disable Font Smoothing.",
							"Caution: Font smoothing is enabled");
			}

			else if (FontSmoothType == 1)
			{
				OH_MessageBox_Error_Warning("It appears that Standard font smoothing is enabled.\n"
							"\n"
							"In order for OpenHoldem to reliably\n"
							"extract information from the poker client\n"
							"you should disable Font Smoothing.",
							"Caution: Font smoothing is enabled");
			}
		}
	}
}
void CConfigurationCheck::CheckColourDepth()
{
	CWindowDC dc(NULL);
	int nBitsPerPixel = dc.GetDeviceCaps(PLANES) * dc.GetDeviceCaps(BITSPIXEL);
	if (nBitsPerPixel < 24)
		OH_MessageBox_Error_Warning("It appears that your Display settings are not configured according to OpenHoldem specifications.\n"
				"24 bit color or higher is needed to reliably extract information from the poker client.\n\n"
				"For more info, look at the manual and the user forums",
				"Caution: Color Depth Too Low");
}
예제 #11
0
void CPreferences::CheckForOutdatedICMConfig() {
  if (prefs_numerical_values[k_prefs_icm_prize1] != kUndefinedZero) {
    OH_MessageBox_Error_Warning(
      "Outdated ICM-configuration\n"
      "\n"
      "OpenHoldem does no longer use the ini-file for that\n"
      "but f$icm_prize1 .. f$icm_prize9 functions\n"
      "\n"
      "Now you can adapt the payout-structure at runtime\n"
      "depending on casino, game-type, number of players...");
  }
}
예제 #12
0
LONG WINAPI MyUnHandledExceptionFilter(EXCEPTION_POINTERS *pExceptionPointers) {
	// Create a minidump
	GenerateDump(pExceptionPointers);

	OH_MessageBox_Error_Warning(
		"OpenHoldem is about to crash.\n"
		"A minidump has been created in your\n"
		"OpenHoldem startup directory.\n"
		"\n"
		"OpenHoldem will shut down when you click OK.",
		"FATAL ERROR");
    return EXCEPTION_EXECUTE_HANDLER;
}
예제 #13
0
void CDlgSAPrefs2::OnOK()
{
	CString			text = "";

	m_FrameDelay.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_FRAMEDELAY)
	{
		OH_MessageBox_Interactive("Invalid Frame Delay", "ERROR", MB_OK);
		return;
	}
	preferences.SetValue(k_prefs_frame_delay, strtoul(text.GetString(), 0, 10));

	m_ClickDelay.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_CLICKDELAY)
	{
		OH_MessageBox_Error_Warning("Invalid Click Delay");
		return;
	}
	preferences.SetValue(k_prefs_click_delay, strtoul(text.GetString(), 0, 10));

	m_SwagDelay1.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_SWAGDELAY1)
	{
		OH_MessageBox_Interactive("Invalid Betsize Delay (Select to Delete)", "ERROR", MB_OK);
		return;
	}
	preferences.SetValue(k_prefs_swag_delay_1, strtoul(text.GetString(), 0, 10));

	m_SwagDelay2.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_SWAGDELAY2)
	{
		OH_MessageBox_Interactive("Invalid Betsize Delay (Delete to Entry)", "ERROR", MB_OK);
		return;
	}
	preferences.SetValue(k_prefs_swag_delay_2, strtoul(text.GetString(), 0, 10));

	m_SwagDelay3.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_SWAGDELAY3) 
	{
		OH_MessageBox_Interactive("Invalid Betsize Delay (Entry to Confirm)", "ERROR", MB_OK);
		return;
	}
	preferences.SetValue(k_prefs_swag_delay_3, strtoul(text.GetString(), 0, 10));

	preferences.SetValue(k_prefs_engage_autoplayer, m_Autoplayer_Upon_Connection.GetCheck()==BST_CHECKED ? true : false);
	preferences.SetValue(k_prefs_restore_position_and_focus, m_Restore_Position_And_Focus.GetCheck()==BST_CHECKED ? true : false);
	preferences.SetValue(k_prefs_use_auto_replay, m_Use_Auto_Replay.GetCheck()==BST_CHECKED ? true : false);
	preferences.SetValue(k_prefs_swag_use_comma, m_SwagUseComma.GetCheck()==BST_CHECKED ? true : false);
	
	CSAPrefsSubDlg::OnOK();
}
예제 #14
0
void CFormula::WarnAboutOutdatedConcepts()
{
	if (DoesFormulaAlreadyExist("f$play"))
	{
		OH_MessageBox_Error_Warning("Your formula set contains a function f$play.\n"
			"The play-formula is an outdated messy concept,\n"
			"that got abolished in OpenHoldem 4.0.0.\n"
			"It got replaced by three separate functions:\n"
			"  * f$sitin\n"
			"  * f$sitout\n"
			"  * f$leave\n"
			"Please refer to the manual about how to adapt\n"
			"your formula set.",
			"Error");
	}
	if (DoesFormulaAlreadyExist("f$swag") 
		|| DoesFormulaAlreadyExist("f$srai")
		|| DoesFormulaAlreadyExist("f$swag_adjust"))
	{
		OH_MessageBox_Error_Warning("Your formula set contains old \"swag\"-functions.\n"
			"\"Swagging\" is an outdated messy concept,\n"
			"where the user had to care about everything.\n\n"
			"f$swag and its supporting functions and symbols\n"
			"got finally replaced by a single function f$betsize\n"
			"and OpenHoldem cares about all the rest automatically\n"
			"(as long as you define the s$betsizemethod correctly).\n\n"
			"Please refer to the manual about how to adapt\n"
			"your formula set.",
			"Error");
	}
	if (DoesFormulaAlreadyExist("f$P"))
	{
		OH_MessageBox_Error_Warning("Your formula set contains old \"prwin\"-functions.\n"
			"\"f$P\" got replaced by \"f$prwin_number_of_opponents\".",
			"Error");
	}

}
예제 #15
0
void CDlgSAPrefs2::OnOK()
{
	CString			text = "";

	m_FrameDelay.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_FRAMEDELAY)
	{
		OH_MessageBox_Interactive("Invalid Frame Delay", "ERROR", MB_OK);
		return;
	}
	prefs.set_frame_delay(strtoul(text.GetString(), 0, 10));

	m_ClickDelay.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_CLICKDELAY)
	{
		OH_MessageBox_Error_Warning("Invalid Click Delay", "ERROR");
		return;
	}
	prefs.set_click_delay(strtoul(text.GetString(), 0, 10));

	m_SwagDelay1.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_SWAGDELAY1)
	{
		OH_MessageBox_Interactive("Invalid Swag Delay (Select to Delete)", "ERROR", MB_OK);
		return;
	}
	prefs.set_swag_delay_1(strtoul(text.GetString(), 0, 10));

	m_SwagDelay2.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_SWAGDELAY2)
	{
		OH_MessageBox_Interactive("Invalid Swag Delay (Delete to Entry)", "ERROR", MB_OK);
		return;
	}
	prefs.set_swag_delay_2(strtoul(text.GetString(), 0, 10));

	m_SwagDelay3.GetWindowText(text);
	if (strtoul(text.GetString(), 0, 10)>MAX_SWAGDELAY3) 
	{
		OH_MessageBox_Interactive("Invalid Swag Delay (Entry to Confirm)", "ERROR", MB_OK);
		return;
	}
	prefs.set_swag_delay_3(strtoul(text.GetString(), 0, 10));

	prefs.set_engage_autoplayer(m_Autoplayer_Upon_Connection.GetCheck()==BST_CHECKED ? true : false);
	prefs.set_swag_use_comma(m_SwagUseComma.GetCheck()==BST_CHECKED ? true : false);
	
	CSAPrefsSubDlg::OnOK();
}
void CConfigurationCheck::CheckInputSettings()
{
	TCHAR KeyboardLayout[KL_NAMELENGTH];
	bool Success = GetKeyboardLayoutName((LPSTR)&KeyboardLayout);

	if (Success && (_tcscmp(KeyboardLayout, k_KeyboardLayout_UK_US_English) != 0))
	{
		OH_MessageBox_Error_Warning("You seem to have non-english keyboard settings.\n"
				"Keyboard settings affect especially the decimal point in numbers\n"
				"and therefore the scraper-engine and the auto-player.\n"
				"If you continue, OpenHoldem may or may not work as expected.\n"
				"If you are an experienced user with a working setup\n"
				"you may turn this warning off.\n"
				"If you are new to OpenHoldem or encounter problems\n"
				"you should fix your keyboard settings\n",
				"Caution: Improper keyboard settings");
	}
}
예제 #17
0
void CDllExtension::Load(const char * path) {
  CString	dll_path;
	if (IsLoaded()) {
     Unload(); 
  }
	// try to load specific path if passed in as a parameter
	if (strlen(path) > 0) {
		dll_path = path;
		 write_log(preferences.debug_dll_extension(),
			"[CDLLExtension] setting path (1) to %s\n", dll_path);
	}	else {
		// Nothing passed in, so we try the DLL of the formula
		// and the DLL from preferences.
		dll_path = p_function_collection->DLLPath();
		 write_log(preferences.debug_dll_extension(),
			"[CDLLExtension] setting path (2) to %s\n", dll_path);
		if (dll_path == "") {
			dll_path = preferences.dll_name().GetString();
			 write_log(preferences.debug_dll_extension(),
				"[CDLLExtension] setting path (3) to %s\n", dll_path);
		}
	}
  p_filenames->SwitchToOpenHoldemDirectory();
	if (dll_path == "")	{
		// Nothing to do
		return;
	}
	_hmod_dll = LoadLibrary(dll_path);
	DWORD dll_error = GetLastError();
  // If the DLL didn't get loaded
	if (_hmod_dll == NULL) {
		CString error_message;
		error_message.Format("Unable to load DLL from:\n"
			"%s\n"
			"error-code: %d\n",
			 dll_path.GetString(), dll_error);
		OH_MessageBox_Error_Warning(error_message, "DLL Load Error");
		return;
	}
	// No longer passing any pointers to the DLL.
	// We do now export functions and link them implicitly:
	// http://www.maxinmontreal.com/forums/viewtopic.php?f=112&t=15470
  DLLOnLoad();
}
예제 #18
0
void CAutoConnector::CheckIfWindowMatchesMoreThanOneTablemap(HWND hwnd) {
  // In OpenHoldem 9.0.1 we replaced clientsize in favour of clientsizemin/max
  // and targetsize. This caused the problem that some people used a very large
  // range of clientsizemin/max in combination with a very common titletext
  // like "Poker". As a consequence some tablemaps connected to nearly every
  // window (not even table).
  // To solve this problem we now detect if a table could be served 
  // by more than one tablemap. For performance reasons we do this exactly once
  // per table at connection.
  // http://www.maxinmontreal.com/forums/viewtopic.php?f=110&t=19407&start=90#p138038
  int num_loaded_tablemaps = p_tablemap_loader->NumberOfTableMapsLoaded();
  int num_matching_tablemaps = 0;
  CString matching_tablemaps = "";
  char text[MAX_WINDOW_TITLE] = { 0 };
  GetWindowText(hwnd, text, sizeof(text));
  CString title = text;
  RECT    crect;
  GetClientRect(hwnd, &crect);

  for (int i=0; i<num_loaded_tablemaps; ++i) {
    // See if it matches the currently loaded(?????) table map
    if (Check_TM_Against_Single_Window(i, hwnd, crect, title)) {
      ++num_matching_tablemaps;
      // Build "list" of matching tablemaps
      matching_tablemaps += p_tablemap_loader->GetTablemapPathToLoad(i);
      matching_tablemaps += "\n";
    }
  }
  if (num_matching_tablemaps > 1) {
    CString error_message;
    error_message.Format("%s%s%s%s%s%s%s%s%s",
      "More then one tablemap fits to the same table\n\n",
      matching_tablemaps,
      "\nTable: ", 
      title,
      "\n\nThese tablemaps need to be adapted:\n",
      "  * clientsizemin/max\n",
      "  * titletext(s)\n",
      "  * and/or tablepoints\n",
      "to make the tablemap-selection-process unambiguous.");
    OH_MessageBox_Error_Warning(error_message);
  }
}
예제 #19
0
CString CFilenames::IniFilename() {
    WIN32_FIND_DATA find_file_data;
    HANDLE h_find;
    CString wildcard = OpenHoldemDirectory() + "\\*.INI";
    CString ini_filename;

    // Try to find "first" ini-file.
    // No matter how it is named -- it is the right one.
    // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx
    h_find = FindFirstFile(wildcard, &find_file_data);
    if (h_find == INVALID_HANDLE_VALUE) {
        // No ini-file found.
        // Use default one (for saving).
        FindClose(h_find);
        Log("IniFilename", k_default_ini_filename);
        return k_default_ini_filename;
    }
    ini_filename = find_file_data.cFileName;
    // Check that no more ini-files exist (potential problems).
    // http://msdn.microsoft.com/en-us/library/windows/desktop/aa364428(v=vs.85).aspx
    if (FindNextFile(h_find, &find_file_data)) {
        FindClose(h_find);
        OH_MessageBox_Error_Warning(
            "More than one ini-file in OpenHoldem-directory.\n"
            "Don't know which one to use.\n"
            "\n"
            "Going to terminate...");
        PostQuitMessage(-1);
        // Previously we returned "a_result_to_make_the_compiler_happy.ini"
        // believing the result was meaning-less and would never be used.
        // However PostQuitMessage(-1) uses a message-queue,
        // so it may take some time, and OH will continue a little bit.
        // Therefore we take the last filename now in order to
        // not create yet another one with a funny name. ;-)
        // http://www.maxinmontreal.com/forums/viewtopic.php?f=156&t=16229
        Log("IniFilename", ini_filename.GetString());
        return ini_filename;
    }
    FindClose(h_find);
    // Exactly one ini-file found
    Log("IniFilename", ini_filename.GetString());
    return ini_filename;
}
예제 #20
0
void CFormula::CreateHandListMatrices()
{
	CString		token = "";

	CSLock lock(m_critsec);

	for (int listnum=0; listnum<MAX_HAND_LISTS; listnum++)
		for (int i=0; i<=12; i++)
			for (int j=0; j<=12; j++)
				_formula.inlist[listnum][i][j] = false;

	for (int i=0; i<(int) _formula.mHandList.GetSize(); i++)
	{
		int listnum = atoi(_formula.mHandList[i].list.Mid(4).GetString());
		if (listnum>=MAX_HAND_LISTS)			
		{
			OH_MessageBox_Error_Warning("List number too high.", "Error");
			break;
		}
		ParseHandList(_formula.mHandList[i].list_text, _formula.inlist[listnum]);
	}
}
예제 #21
0
double CParseTreeNode::EvaluateBinaryExpression(bool log) {
  assert(_first_sibbling  != NULL);
  assert(_second_sibbling != NULL);
  assert(_third_sibbling  == NULL);
  assert(_terminal_name == "");
	double value_of_first_sibbling  = EvaluateSibbling(_first_sibbling, log);
	double value_of_second_sibbling = 0.0;
	// Short circuiting
	// Don't evaluate unnecessary parts of expressions
	if (_node_type == kTokenOperatorLogicalAnd)	{
		if (value_of_first_sibbling == false) {
			return false;
		}
		value_of_second_sibbling = EvaluateSibbling(_second_sibbling, log);
		return (value_of_second_sibbling ? true : false);
	}	else if (_node_type == kTokenOperatorLogicalOr)	{
    // Attention!
    // We can not look here for "value_of_first_sibbling == true"
    // because this way we would only accept true (==1)
    // but we want to accept any non-zero value.
    // http://www.maxinmontreal.com/forums/viewtopic.php?f=111&t=17899
		if (value_of_first_sibbling) {
			return true;
		}
		value_of_second_sibbling = EvaluateSibbling(_second_sibbling, log);
		return (value_of_second_sibbling ? true : false);
	}
	// Short circuiting done
	// Now normal evaluation of operators that need both operands
	value_of_second_sibbling = EvaluateSibbling(_second_sibbling, log);
	switch (_node_type) {
	  case kTokenOperatorPlus: 
		  return value_of_first_sibbling + value_of_second_sibbling;
	  case kTokenOperatorMinus: 
		  return value_of_first_sibbling - value_of_second_sibbling;
	  case kTokenOperatorMultiplication: 
		  return value_of_first_sibbling * value_of_second_sibbling;
	  case kTokenOperatorDivision: 
		  if (value_of_second_sibbling == 0) {
			  OH_MessageBox_Error_Warning("Division by zero.");
			  return kUndefined;
		  } else {
			  return value_of_first_sibbling / value_of_second_sibbling;
		  }
	  case kTokenOperatorModulo: 
      if (value_of_second_sibbling == 0) {
			  OH_MessageBox_Error_Warning("Division by zero.");
			  return kUndefined;
		  } else {
			  return (unsigned long)value_of_first_sibbling 
				  % (unsigned long)value_of_second_sibbling;
		  }
	  case kTokenOperatorExponentiation: 
		  return pow(value_of_first_sibbling, value_of_second_sibbling);
	  case kTokenOperatorEquality: 
		  return IsEqual(value_of_first_sibbling, value_of_second_sibbling);
	  case kTokenOperatorApproximatellyEqual: 
		  return IsApproximatellyEqual(value_of_first_sibbling, value_of_second_sibbling);
	  case kTokenOperatorSmaller: 
		  return IsSmaller(value_of_first_sibbling, value_of_second_sibbling);
	  case kTokenOperatorSmallerOrEqual: 
		  return IsSmallerOrEqual(value_of_first_sibbling, value_of_second_sibbling);
	  case kTokenOperatorGreater: 
		  return IsGreater(value_of_first_sibbling, value_of_second_sibbling);
	  case kTokenOperatorGreaterOrEqual: 
		  return IsGreaterOrEqual(value_of_first_sibbling, value_of_second_sibbling);
	  case kTokenOperatorNotEqual: 
	  case kTokenOperatorLogicalXOr: 
		  return value_of_first_sibbling != value_of_second_sibbling;
	  case kTokenOperatorBinaryAnd: 
		  return (unsigned long)value_of_first_sibbling 
			  & (unsigned long)value_of_second_sibbling;
	  case kTokenOperatorBinaryOr: 
		  return (unsigned long)value_of_first_sibbling 
			  | (unsigned long)value_of_second_sibbling;
	  case kTokenOperatorBinaryXOr: 
		  return (unsigned long)value_of_first_sibbling 
			  ^ (unsigned long)value_of_second_sibbling;
	  case kTokenOperatorBitShiftLeft: 
		  return (unsigned long)value_of_first_sibbling 
			  << (unsigned long)value_of_second_sibbling;
	  case kTokenOperatorBitShiftRight: 
		  return (unsigned long)value_of_first_sibbling 
			  >> (unsigned long)value_of_second_sibbling;
	  case kTokenOperatorPercentage: 
		  return value_of_first_sibbling * value_of_second_sibbling * 0.01;
	  default: assert(false);
	}
	return kUndefined;
}
예제 #22
0
// COpenHoldemApp initialization
BOOL COpenHoldemApp::InitInstance()
{
	Scintilla_RegisterClasses(AfxGetInstanceHandle());

	// Initialize richedit2 library
	AfxInitRichEdit2();

	// Change class name of Dialog
	WNDCLASS wc;
	GetClassInfo(AfxGetInstanceHandle(), "#32770", &wc);

	wc.lpszClassName = "OpenHoldemFormula";
	wc.hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
	RegisterClass(&wc);

	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	// Since OH 4.0.0 we always use an ini-file,
	// the one and only in our OH-directory,
	// no matter how it is named.
	// For the technical details please see:
	// http://msdn.microsoft.com/de-de/library/xykfyy20(v=vs.80).aspx
	InstantiateSomeSingletonsForVeryEarlyUseInInitInstance();
	free((void*)m_pszProfileName);
	m_pszProfileName = _strdup(p_filenames->IniFilePath().GetString());
	prefs.LoadPreferences();
	
	// Classes
	if (!p_sessioncounter) p_sessioncounter = new CSessionCounter;
	// Start logging immediatelly after the loading the preferences
	// and initializing the sessioncounter.
	start_log();
	InstantiateAllSingletons();

	// mouse.dll - failure in load is fatal
	_mouse_dll = LoadLibrary("mouse.dll");
	if (_mouse_dll==NULL)
	{
		CString		t = "";
		t.Format("Unable to load mouse.dll, error: %d\n\nExiting.", GetLastError());
		OH_MessageBox_Error_Warning(t, "OpenHoldem mouse.dll ERROR");
		return false;
	}
	else
	{
		_dll_mouse_process_message = (mouse_process_message_t) GetProcAddress(_mouse_dll, "ProcessMessage");
		_dll_mouse_click = (mouse_click_t) GetProcAddress(_mouse_dll, "MouseClick");
		_dll_mouse_click_drag = (mouse_clickdrag_t) GetProcAddress(_mouse_dll, "MouseClickDrag");

		if (_dll_mouse_process_message==NULL || _dll_mouse_click==NULL || _dll_mouse_click_drag==NULL)
		{
			CString		t = "";
			t.Format("Unable to find all symbols in mouse.dll");
			OH_MessageBox_Error_Warning(t, "OpenHoldem mouse.dll ERROR");

			FreeLibrary(_mouse_dll);
			_mouse_dll = NULL;
			return false;
		}
	}

	// keyboard.dll - failure in load is fatal
	_keyboard_dll = LoadLibrary("keyboard.dll");
	if (_keyboard_dll==NULL)
	{
		CString		t = "";
		t.Format("Unable to load keyboard.dll, error: %d\n\nExiting.", GetLastError());
		OH_MessageBox_Error_Warning(t, "OpenHoldem keyboard.dll ERROR");
		return false;
	}
	else
	{
		_dll_keyboard_process_message = (keyboard_process_message_t) GetProcAddress(_keyboard_dll, "ProcessMessage");
		_dll_keyboard_sendstring = (keyboard_sendstring_t) GetProcAddress(_keyboard_dll, "SendString");
		_dll_keyboard_sendkey = (keyboard_sendkey_t) GetProcAddress(_keyboard_dll, "SendKey");

		if (_dll_keyboard_process_message==NULL || _dll_keyboard_sendstring==NULL || _dll_keyboard_sendkey==NULL)
		{
			CString		t = "";
			t.Format("Unable to find all symbols in keyboard.dll");
			OH_MessageBox_Error_Warning(t, "OpenHoldem keyboard.dll ERROR");

			FreeLibrary(_keyboard_dll);
			_keyboard_dll = NULL;
			return false;
		}
	}

	MyLoadStdProfileSettings(k_number_of_last_recently_used_files_in_file_menu);
	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CSingleDocTemplate* pDocTemplate;

	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(COpenHoldemDoc),
		RUNTIME_CLASS(CMainFrame),	   // main SDI frame window
		RUNTIME_CLASS(COpenHoldemView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);

	EnableShellOpen();
	RegisterShellFileTypes(false);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Open the most recently saved file. (First on the MRU list.) Get the last
	// file from the registry. We need not account for cmdInfo.m_bRunAutomated and
	// cmdInfo.m_bRunEmbedded as they are processed before we get here.
	if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
	{
		CString sLastPath(GetProfileString(_afxFileSection, "File1"));

		if (! sLastPath.IsEmpty())
		{
			CFile f;

			// If file is there, set to open!
			if (f.Open(sLastPath, CFile::modeRead | CFile::shareDenyWrite))
			{
				cmdInfo.m_nShellCommand = CCommandLineInfo::FileOpen;
				cmdInfo.m_strFileName = sLastPath;
				f.Close();
			}
		}
	}

	// Dispatch commands specified on the command line.  Will return FALSE if
	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;

	if (prefs.simple_window_title())
		m_pMainWnd->PostMessage(WMA_SETWINDOWTEXT, 0, (LPARAM)NULL);

	// The one and only window has been initialized, so show and update it
	if (prefs.gui_start_minimized())
	{
		m_pMainWnd->ShowWindow(SW_MINIMIZE);
	}
	else
	{
		m_pMainWnd->ShowWindow(SW_SHOW);
	}
	m_pMainWnd->UpdateWindow();
	// call DragAcceptFiles only if there's a suffix
	//  In an SDI app, this should occur after ProcessShellCommand
	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	// Bring main window to front
	m_pMainWnd->SetWindowPos(&CWnd::wndTop, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
	m_pMainWnd->SetActiveWindow();
	m_pMainWnd->SetFocus();
	m_pMainWnd->SetForegroundWindow();

	// autoconnect on start, if preferred
	if (prefs.autoconnector_when_to_connect() == k_AutoConnector_Connect_Once)
	{
		p_autoconnector->Connect(NULL);
	}
	// Start thread anyway; permanent connection might be enabled later via preferences.
	p_autoconnectorthread->StartThread();	

	return TRUE;
}
예제 #23
0
void CReplayFrame::CreateReplayFrame(void)
{
	FILE			*fp = NULL;
	int				i = 0;
	time_t			ltime = 0;
	tm				now_time = {0};
	char			now_time_str[100] = {0};
	ULARGE_INTEGER	free_bytes_for_user_on_disk = {0}, 
					total_bytes_on_disk = {0}, 
					free_bytes_total_on_disk = {0};
	int				e = SUCCESS;

	//  Sanity check: Enough disk-space for replay frame?	
	GetDiskFreeSpaceEx(
		p_filenames->OpenHoldemDirectory(),  //  Directory on disk of interest
		&free_bytes_for_user_on_disk,  
		&total_bytes_on_disk,	
		&free_bytes_total_on_disk);
	if (free_bytes_for_user_on_disk.QuadPart < FREE_SPACE_NEEDED_FOR_REPLAYFRAME) 
	{
		write_log(prefs.debug_replayframes(), "[CReplayFrame] Not enough disk-space\n");
		OH_MessageBox_Error_Warning("Not enough disk space to create replay-frame.", "ERROR");

		return;
	}

	// Get current time
	time(&ltime);
	localtime_s(&now_time, &ltime);
	strftime(now_time_str, 100, "%Y-%m-%d %H:%M:%S", &now_time);

	// Get exclusive access to CScraper and CSymbols variables
	// (Wait for scrape/symbol cycle to finish before saving frame)
	EnterCriticalSection(&p_heartbeat_thread->cs_update_in_progress);
	CreateBitMapFile();

	// Create HTML file
	CString path = p_filenames->ReplayHTMLFilename(_next_replay_frame);
	if (fopen_s(&fp, path.GetString(), "w")==0)
	{
		write_log(prefs.debug_replayframes(), "[CReplayFrame] Creating HTML file: $s\n", path);
		// First line has to be the "title" of the table.
		// This is no longer valid HTML, but the way Ray.E.Bornert did it
		// for WinHoldem and WinScrape.
		fprintf(fp, "%s\n", p_scraper->title());
		// HTML header
		fprintf(fp, "<html>\n");
		fprintf(fp, "  <head>\n");
		fprintf(fp, "    <title>%s</title>\n", p_scraper->title());
		fprintf(fp, "  </head>");
		fprintf(fp, "<style>\n");
		fprintf(fp, "td {text-align:right;}\n");
		fprintf(fp, "</style>\n");
		fprintf(fp, "<body>\n");
		fprintf(fp, "<font face=courier>\n");

		// Bitmap image
		fprintf(fp, "<img src=\"frame%06d.bmp\">\n", _next_replay_frame);
		fprintf(fp, "<br>\n");

		// Table title
		fprintf(fp, "[%s]", p_scraper->title());
		fprintf(fp, "<br>\n");

		// Session, frame number and time
		fprintf(fp, " [Session %lu]", p_sessioncounter->session_id());
		fprintf(fp, " [Frame: %06d]", _next_replay_frame);
		fprintf(fp, " [%s]<br>\n", now_time_str);
		fprintf(fp, "<br>\n");

		// Links forwards and backwards to the next frames
		fprintf(fp, "%s", LPCSTR(GetLinksToPrevAndNextFile()));
		fprintf(fp, "<br>\n");
		fprintf(fp, "<br>\n");

		// Header of main table for smaller data tables
		fprintf(fp, "<table>\n");
		fprintf(fp, "<tr>\n");
		fprintf(fp, "<td>\n");

		// Data tables
		fprintf(fp, "%s", LPCSTR(GetPlayerInfoAsHTML()));
		fprintf(fp, "/<td>\n");
		fprintf(fp, "<td>\n");
		fprintf(fp, "%s", LPCSTR(GetButtonStatesAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetBlindInfoAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetCommonCardsAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetPotsAsHTML()));
		fprintf(fp, "</td>\n");

		// Footer of main table
		fprintf(fp, "</tr>\n");
		fprintf(fp, "</table>\n");

		// End of HTML
		fprintf(fp, "</body></html>\n");

		fclose(fp);
	}	

	LeaveCriticalSection(&p_heartbeat_thread->cs_update_in_progress);
}
예제 #24
0
void CDllExtension::LoadDll(const char * path)
{
    CString		dll_path;

    if (_hmod_dll != NULL)
        return;

    // try to load specific path if passed in as a parameter
    if (strlen(path) > 0)
    {
        dll_path = path;
        write_log(preferences.debug_dll_extension(),
                  "[CDLLExtension] setting path (1) to %s\n", dll_path);
    }
    else
    {
        // Nothing passed in, so we try the DLL of the formula
        // and the DLL from preferences.
        dll_path = GetDLLSpecifiedInFormula();
        write_log(preferences.debug_dll_extension(),
                  "[CDLLExtension] setting path (2) to %s\n", dll_path);
        if (dll_path == "")
        {
            dll_path = preferences.dll_name().GetString();
            write_log(preferences.debug_dll_extension(),
                      "[CDLLExtension] setting path (3) to %s\n", dll_path);
        }
    }

    if (dll_path == "")
    {
        // Nothing to do
        return;
    }
    p_filenames->SwitchToOpenHoldemDirectory();
    _hmod_dll = LoadLibrary(dll_path);
    DWORD dll_error = GetLastError();

    // If the DLL didn't get loaded
    if (_hmod_dll == NULL)
    {
        CString error_message;
        error_message.Format("Unable to load DLL from:\n"
                             "%s\n"
                             "error-code: %d\n",
                             dll_path.GetString(), dll_error);
        OH_MessageBox_Error_Warning(error_message, "DLL Load Error");
        return;
    }

    // Get address of process_message from dll
    // user.dll, as defined in WinHoldem, does not ship with a .def file by default - we must use the ordinal method to get the address
    //global.process_message = (process_message_t) GetProcAddress(global._hmod_dll, "process_message");
    _process_message = (process_message_t) ::GetProcAddress(_hmod_dll, (LPCSTR) 1);

    if (_process_message==NULL)
    {
        CString error_message;
        error_message.Format("Unable to find process_message in dll");
        OH_MessageBox_Error_Warning(error_message, "DLL Load Error");

        FreeLibrary(_hmod_dll);
        _hmod_dll = NULL;
        return;
    }
    // pass "load" message
    (_process_message) ("event", "load");

    // No longer passing any pointers to the DLL.
    // We do no export functions an link them implicitly:
    // http://www.maxinmontreal.com/forums/viewtopic.php?f=112&t=15470

    // To do !! Create a function if necessary
    //pass "history" message (address of history structure)
    //  2010-01-23 Demonthus
    //(_process_message) ("history", p_handhistory->history());
}
bool CSymbolEnginePokerTracker::EvaluateSymbol(const char *name, double *result, bool log /* = false */)
{
  FAST_EXIT_ON_OPENPPL_SYMBOLS(name);
	if (memcmp(name,"pt_",3)!=0)
	{
		// Symbol of a different symbol-engine
		return false;
	}
	CString s = name;
	CheckForChangedPlayersOncePerHeartbeatAndSymbolLookup();
	if (IsOldStylePTSymbol(s))
	{
		CString error_message;
		error_message.Format(
			"Old style PokerTracker symbol detected: %s.\n"
			"\n"
			"PokerTracker symbol start with \"pt_\".\n"
      "Possible postfixes:\n"
      "  * chair number (0..9)\n"
      "  * _raischair\n"
      "  * _headsup\n"
      "  * _smallblind\n"
      "  * _bigblind\n"
      "  * _dealer\n"
      "  * _cutoff\n"
      "  * _user\n"
      "  * _firstraiser\n"
      "  * _firstcaller\n"
      "  * _lastcaller\n", s);
		OH_MessageBox_Formula_Error(
			error_message,			 
			"ERROR: Invalid PokerTracker Symbol");
		*result = kUndefined;
		return true;
	}
	if (!PT_DLL_IsValidSymbol(CString(s)))
	{
		// Invalid PokerTracker symbol
		WarnAboutInvalidPTSymbol(s);
		*result = kUndefined;
		return true;
	}
	int chair = 0;

	if (!p_pokertracker_thread->IsConnected()) 	{
		if (!p_symbol_engine_userchair->userchair_confirmed() || p_formula_parser->IsParsing()) {
			// We are not yet seated or formula is getting parsed.
			// Symbol-lookup happens, because of Formula-validation.
			// Not a problem, if we do not yet have a DB-connection.
			// Don't throw a warning here.
       write_log(preferences.debug_pokertracker(), "[PokerTracker] Not yet seated or formula parsing.\n");
		} else {
			// We are seated and playing.
			// Serious problem, if we do not have a DB-connection.
			OH_MessageBox_Error_Warning("Not connected to PokerTracker database.\n"
				"Can't use PokerTracker symbols.");
		}
		*result = kUndefined;
		return true;
	}

	CString standard_symbol_name;
	assert(StringAIsPrefixOfStringB("pt_", s));
	// PokerTracker symbols for the raise-chair
	if (s.Right(10) == "_raischair") {
		chair = p_symbol_engine_raisers->raischair();
	}
	// PokerTracker symbols for the opponent headsup chair
	else if (s.Right(8) == "_headsup") {
    chair = p_symbol_engine_chairs->opponent_headsup_chair();
	}
  // PokerTracker symbols for the smallblind chair
	else if (s.Right(11) == "_smallblind") {
    chair = p_symbol_engine_chairs->smallblind_chair();
	}
  // PokerTracker symbols for the bigblind chair
	else if (s.Right(9) == "_bigblind") {
    chair = p_symbol_engine_chairs->bigblind_chair();
	}
  // PokerTracker symbols for the cutoff chair
	else if (s.Right(7) == "_cutoff") {
    chair = p_symbol_engine_chairs->cutoff_chair();
	}
  // PokerTracker symbols for the firstcaller chair
	else if (s.Right(12) == "_firstcaller") {
    chair = p_symbol_engine_callers->firstcaller_chair();
	}
  // PokerTracker symbols for the lastcaller chair
	else if (s.Right(11) == "_lastcaller") {
    chair = p_symbol_engine_callers->lastcaller_chair();
	}
  // PokerTracker symbols for the firstraiser chair
	else if (s.Right(12) == "_firstraiser") {
		chair = p_symbol_engine_raisers->firstraiser_chair();
	}
  // PokerTracker symbols for the dealerchair chair
	else if (s.Right(7) == "_dealer") {
    chair = p_symbol_engine_dealerchair->dealerchair();
	}
  // PokerTracker symbols for the  chair
	else if (s.Right(5) == "_user") {
    chair = p_symbol_engine_userchair->userchair();
	}
  // PokerTracker symbols for chair X
	else {
		CString symbol = s;
		CString last_character = symbol.Right(1);
    if (!isdigit(last_character[0])) {
      CString error_message;
      error_message.Format("Invalid PokerTracker Symbol: &s",
        symbol);
      OH_MessageBox_Formula_Error(error_message, "ERROR");
		  *result = kUndefined;
      return false;
    }
		chair = atoi(last_character);
	}
  // Catch undefined chair (e.g. pt_r_-symbol without raisee)
  if (chair < 0) {
    *result = kUndefined;
    return true;
  }
	AssertRange(chair, kFirstChair, kLastChair);
	*result = PT_DLL_GetStat(s, chair); 
	return true;
}
예제 #26
0
void CFormula::CopyFormulaFrom(CFormula *f)
{
	SHandList		list;
	SFunction		func;
	int				from_count = 0, to_count = 0;
	bool			addit = false, deleteit = false;

	// Init locals
	list.list = "";
	list.list_text = "";
	func.cache = 0.;
	func.dirty = false;
	func.fresh = false;
	func.func = "";
	func.func_text = "";

	CSLock lock(m_critsec);

	// handle deleted udfs
	to_count = (int) _formula.mFunction.GetSize();
	for (int to_iter=0; to_iter<to_count; to_iter++)
	{
		from_count = (int) f->formula()->mFunction.GetSize();
		deleteit = true;
		for (int from_iter=0; from_iter<from_count; from_iter++)
		{
			if (_formula.mFunction[to_iter].func == f->formula()->mFunction[from_iter].func)
			{
				deleteit = false;
				from_iter = from_count+1;
			}
		}
		if (deleteit)
		{
			_formula.mFunction.RemoveAt(to_iter, 1);
			to_count = (int) _formula.mFunction.GetSize();
			to_iter-=1;
		}
	}

	// handle new/changed udfs
	from_count = (int) f->formula()->mFunction.GetSize();
	for (int from_iter=0; from_iter<from_count; from_iter++)
	{
		to_count = (int) _formula.mFunction.GetSize();
		addit = true;
		for (int to_iter=0; to_iter<to_count; to_iter++)
		{
			if (_formula.mFunction[to_iter].func == f->formula()->mFunction[from_iter].func)
			{
				// changed?
				addit = false;
				if (_formula.mFunction[to_iter].func_text == f->formula()->mFunction[from_iter].func_text)
				{
					// no change
					_formula.mFunction[to_iter].dirty = false;
					_formula.mFunction[to_iter].fresh = false;
				}
				else
				{
					// yup, it changed
					_formula.mFunction[to_iter].func_text = f->formula()->mFunction[from_iter].func_text;
					_formula.mFunction[to_iter].dirty = true;
					_formula.mFunction[to_iter].fresh = false;
					_formula.mFunction[to_iter].cache = 0.0;
				}
				to_iter = to_count+1;
			}
		}

		// new
		if (addit)
		{
			func.func = f->formula()->mFunction[from_iter].func;
			func.func_text = f->formula()->mFunction[from_iter].func_text;
			func.dirty = true;
			func.fresh = false;
			func.cache = 0.0;
			_formula.mFunction.Add(func);
		}
	}

	// Copy hand lists
	_formula.mHandList.RemoveAll();
	from_count = (int) f->formula()->mHandList.GetSize();
	for (int from_iter=0; from_iter<from_count; from_iter++)
	{
		list.list = f->formula()->mHandList[from_iter].list;
		list.list_text = f->formula()->mHandList[from_iter].list_text;
		if (DoesFormulaAlreadyExist(list.list))
		{
			CString ErrorMessage = "Handlist does already exist: " + list.list;
			OH_MessageBox_Error_Warning(ErrorMessage, "Error");
		}
		else
		{
			_formula.mHandList.Add(list); 
		}
	}

	// Copy name
	_formula_name = f->formula_name();
}
예제 #27
0
void CReplayFrame::CreateReplayFrame(void){
	FILE	*fp = NULL;
	ULARGE_INTEGER	free_bytes_for_user_on_disk = {0}, 
	total_bytes_on_disk = {0}, 
	free_bytes_total_on_disk = {0};
	//  Sanity check: Enough disk-space for replay frame?	
	GetDiskFreeSpaceEx(
		p_filenames->OpenHoldemDirectory(),  //  Directory on disk of interest
		&free_bytes_for_user_on_disk,  
		&total_bytes_on_disk,	
		&free_bytes_total_on_disk);
	if (free_bytes_for_user_on_disk.QuadPart < FREE_SPACE_NEEDED_FOR_REPLAYFRAME) {
		write_log(preferences.debug_replayframes(), "[CReplayFrame] Not enough disk-space\n");
		OH_MessageBox_Error_Warning("Not enough disk space to create replay-frame.");
    return;
	}
	// Get exclusive access to CScraper and CSymbols variables
	// (Wait for scrape/symbol cycle to finish before saving frame)
	EnterCriticalSection(&p_heartbeat_thread->cs_update_in_progress);
  CString next_frame;
	next_frame.Format("[%06d]", _next_replay_frame);
  // Replay-frame should always be mentioned in the log for easy reference
  write_log(k_always_log_basic_information, "[CReplayFrame] Shooting frame %s\n", next_frame);
	CreateBitMapFile();
  // Create HTML file
	CString path = p_filenames->ReplayHTMLFilename(_next_replay_frame);
	if (fopen_s(&fp, path.GetString(), "w")==0) {
		write_log(preferences.debug_replayframes(), "[CReplayFrame] Creating HTML file: %s\n", path);
		// First line has to be the "title" of the table.
		// This is no longer valid HTML, but the way Ray.E.Bornert did it
		// for WinHoldem and WinScrape.
		fprintf(fp, "%s\n", p_table_state->TableTitle()->Title());
    fprintf(fp, "<br>\n");
		// HTML header
		fprintf(fp, "<html>\n");
		fprintf(fp, "  <head>\n");
		fprintf(fp, "    <title>%s</title>\n", p_table_state->TableTitle()->Title());
		fprintf(fp, "  </head>");
		fprintf(fp, "<style>\n");
		fprintf(fp, "td {text-align:right;}\n");
		fprintf(fp, "</style>\n");
		fprintf(fp, "<body>\n");
		fprintf(fp, "<font face=courier>\n");
    // Bitmap image
		fprintf(fp, "<img src=\"frame%06d.bmp\">\n", _next_replay_frame);
		fprintf(fp, "<br>\n");
    // Title, data, frame-number, OH-version
    fprintf(fp, "%s", GeneralInfo());
    // Links forwards and backwards to the next frames
		fprintf(fp, "%s", LPCSTR(GetLinksToPrevAndNextFile()));
		fprintf(fp, "<br>\n");
		fprintf(fp, "<br>\n");
    // Header of main table for smaller data tables
		fprintf(fp, "<table>\n");
		fprintf(fp, "<tr>\n");
		fprintf(fp, "<td>\n");
    // Data tables
		fprintf(fp, "%s", LPCSTR(GetPlayerInfoAsHTML()));
		fprintf(fp, "/<td>\n");
		fprintf(fp, "<td>\n");
		fprintf(fp, "%s", LPCSTR(GetButtonStatesAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetBlindInfoAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetCommonCardsAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetPotsAsHTML()));
		fprintf(fp, "</td>\n");
    // Footer of main table
		fprintf(fp, "</tr>\n");
		fprintf(fp, "</table>\n");
    // End of HTML
		fprintf(fp, "</body></html>\n");
    fclose(fp);
	}	
  LeaveCriticalSection(&p_heartbeat_thread->cs_update_in_progress);
}
예제 #28
0
// Reading a part of a formula, which may be spread
// between two files in case of an old style whf / whx formula.
void CFormula::ReadFormulaFile(CArchive& ar, bool ignoreFirstLine)
{
	CString		strOneLine = ""; 
	int			content = 0;
	char		funcname[k_max_size_of_function_name] = {0};
	int			start = 0, end = 0;
		
	SFunction	func;	
	SHandList	list;		

	CSLock lock(m_critsec);

	// Ignore first line (date/time)
	if (ignoreFirstLine)
		ar.ReadString(strOneLine);

	// read data in, one line at a time
	strOneLine = "";
	content = FTnone;
	func.func = "";
	while(ar.ReadString(strOneLine)) 
	{ 
		// If this line marks the beginning of a function, then save the previously
		// collected function, and start a new one
		if (strOneLine.Mid(0,2)=="##") 
		{
			// Save the previously collected function
			if (content == FTlist) 
			{
				// Strip the LFCR off the last line (we need to add CRLF for all but the last line)
				list.list_text.TrimRight("\r\n");
				if (DoesFormulaAlreadyExist(list.list))
				{
					CString ErrorMessage = "Handlist does already exist: " + list.list;
					OH_MessageBox_Error_Warning(ErrorMessage, "Error");
				}
				else
				{
					_formula.mHandList.Add(list); 
				}
			}
			else if (content == FTfunc) 
			{
				func.func_text.TrimRight("\r\n");
				if (DoesFormulaAlreadyExist(func.func))
				{
					CString ErrorMessage = "Function does already exist: " + func.func;
					OH_MessageBox_Error_Warning(ErrorMessage, "Error");
				}
				else
				{
					_formula.mFunction.Add(func);
				}
			}
			// Get the function name				
			start = strOneLine.Find("##",0);

			// No need to check the result of start,
			// as this code gets executed only,
			// if a line starts with "##"	
			end = strOneLine.Find("##", start+2);

			// Checking for malformed function header
			// without trailing "##"
			if (end == k_undefined) 
			{
				// Trying to continue gracefully.				
				// Skipping is not possible,
				// as this crashes the formula editor.											
				int number_of_chars_to_copy = (strOneLine.GetLength() < k_max_size_of_function_name) ?
					strOneLine.GetLength() : k_max_size_of_function_name;
				strncpy_s(funcname, 
					k_max_size_of_function_name, 
					strOneLine.GetString()+start+2,
					number_of_chars_to_copy);
				funcname[number_of_chars_to_copy]='\0';
				
				CString the_ErrorMessage = "Malformed function header!\nMissing trailing '##'.\n" 
					+ strOneLine + "\n"
					+ "Trying to continue...";
				OH_MessageBox_Error_Warning(the_ErrorMessage, "Syntax Error");
			}

			else 
			{
				int size_of_function_name = end - start + 1;    
				assert(size_of_function_name < k_max_size_of_function_name);
				// strncpy_s: http://msdn.microsoft.com/de-de/library/5dae5d43(v=vs.80).aspx
				strncpy_s(funcname,                              // Destination
					k_max_size_of_function_name * sizeof(char),  // Size of destination
					strOneLine.GetString() + start + 2,          // Start of source (without leading "##")
					size_of_function_name);						 // Elements to copy	
				funcname[end-2] = '\0';							 // Remove trailing "##"	
			}

			if (memcmp(funcname, "list", 4) == 0) 
			{ 
				content = FTlist;
				list.list = funcname;
				list.list_text = "";
			}

			else 
			{
				content = FTfunc;
				func.func = funcname;
				func.func_text = "";
				func.dirty = true;
			}
		}

		// Get the function content
		else 
		{
			switch (content) 
			{
				 case FTlist:
					 list.list_text.Append(strOneLine); list.list_text.Append("\r\n");
					 break;
				 case FTfunc:
					 func.func_text.Append(strOneLine); func.func_text.Append("\r\n");
					 break;
			}
		}	
	}  

	// Add the last list/function to the CArray on EOF, if it was a list being processed
	if (content == FTlist) 
	{
		list.list_text.TrimRight("\r\n");
		if (DoesFormulaAlreadyExist(list.list))
		{
			CString ErrorMessage = "Handlist does already exist: " + list.list;
			OH_MessageBox_Error_Warning(ErrorMessage, "Error");
		}
		else
		{
			_formula.mHandList.Add(list); 
		}
	}
	else if (content == FTfunc) 
	{
		func.func_text.TrimRight("\r\n");
		if (DoesFormulaAlreadyExist(func.func))
		{
			CString ErrorMessage = "Function does already exist: " + func.func;
			OH_MessageBox_Error_Warning(ErrorMessage, "Error");
		}
		else
		{
			_formula.mFunction.Add(func);
		}
	}
}
예제 #29
0
bool CFormula::ParseLoop(const CUPDUPDATA* pCUPDUPData)
{
	int				i = 0, j = 0, N = 0;
	CString			s = "";
	bool			result = false;
	int				stopchar = 0;
	int				c = 0, linenum = 0, colnum = 0;
	LARGE_INTEGER	bcount = {0}, ecount = {0}, lFrequency = {0};
	double			time_elapsed = 0.;
	sData			*data = (sData*) (pCUPDUPData->GetAppData());
	CGrammar		gram;
	bool            gui_enable_progress_dialog = !prefs.gui_disable_progress_dialog();

	pCUPDUPData->SetProgress("", 0, false);

	// init timer
	QueryPerformanceCounter(&bcount);
	QueryPerformanceFrequency(&lFrequency);

	N = (int) data->pParent->formula()->mFunction.GetSize();
	for (int i=0; i<N; i++)
	{

		// Update progress dialog
		s.Format("Parsing formula set %s : %.0f%%", data->pParent->formula()->mFunction[i].func.GetString(), (double) i / (double) N * 100.0);
		QueryPerformanceCounter(&ecount);
		time_elapsed = ((double) (ecount.LowPart - bcount.LowPart))/((double) lFrequency.LowPart);
		pCUPDUPData->SetProgress(s.GetString(), (int) ((double) i / (double) N * 100.0), ((time_elapsed>=3.0) && gui_enable_progress_dialog));

		// Parse it if it is dirty, and not notes, dll or f$debug
		if (data->pParent->formula()->mFunction[i].dirty == true &&
				data->pParent->formula()->mFunction[i].func != "notes" &&
				data->pParent->formula()->mFunction[i].func != "dll" &&
				data->pParent->formula()->mFunction[i].func != "f$debug")
		{
			result = gram.ParseString(
							&data->pParent->formula()->mFunction[i].func_text, 
							data->pParent->formula(), 
							data->pParent->set_tpi(i), 
							&stopchar);

			if (!result)
			{
				linenum = colnum = 1;
				for (c=0; c<stopchar; c++)
				{
					if (data->pParent->formula()->mFunction[i].func_text.Mid(c, 1)=="\n")
					{
						linenum++;
						colnum = 1;
					}
					else
					{
						colnum++;
					}
				}
				s.Format("Error in parse of %s\nLine: %d  Character: %d\n\nNear:\n \"%s\"",
					 data->pParent->formula()->mFunction[i].func.GetString(),
					 linenum, colnum,
					 data->pParent->formula()->mFunction[i].func_text.Mid(stopchar, 40).GetString());
				OH_MessageBox_Error_Warning(s, "PARSE ERROR");

				data->all_parsed = false;
			}

			else if (gram.parse_symbol_stop_strs()->GetSize() != 0)
			{
				s.Format("Error in parse of %s\n\nInvalid symbols:\n",
					 data->pParent->formula()->mFunction[i].func.GetString());
				for (int j=0; j<gram.parse_symbol_stop_strs()->GetSize(); j++)
				{
					s.Append("   ");
					s.Append(gram.parse_symbol_stop_strs()->GetAt(j).c_str());
					s.Append("\n");
				}
				OH_MessageBox_Error_Warning(s, "PARSE ERROR");

				data->all_parsed = false;
			}

			else
			{
				data->pParent->set_func_dirty(i, false);
			}
		}
	}
	pCUPDUPData->SetProgress("", 100, gui_enable_progress_dialog);

	return true;
}