Пример #1
0
/*!
	remove a NativeWindow -> QTMovieWindowH association
 */
void unregister_QTMovieWindowH_from_NativeWindow( NativeWindow hwnd )
{
	if( nw2q_initialised && hwnd && hwnd2qtwmh.count(hwnd) ){
		hwnd2qtwmh.erase(hwnd);
		hwnd2qtwmh.resize(0);
	}
}
Пример #2
0
/*!
	unregisters a QTMovieWindowH from Movie association
 */
void unregister_QTMovieWindowH_for_Movie( Movie movie )
{
	if( movie && m2qtmwh_initialised && m2qtmwh.count(movie) ){
		m2qtmwh.erase(movie);
		m2qtmwh.resize(0);
	}
}
void PatchMW2_StringList()
{
	slHashMap.set_empty_key("*DUMMYDUMMY*");
	slHashMap.set_deleted_key("*DUMMYDUMM*");

	call(0x4D2280, SL_Init, PATCH_JUMP);
	call(0x436B40, SL_GetStringOfSize, PATCH_JUMP);
	call(0x4EC1D0, SL_ConvertToString_, PATCH_JUMP);
	call(0x61BCB0, FindStringOfSize, PATCH_JUMP);
	call(0x469D80, SL_ConvertFromString, PATCH_JUMP);
	call(0x4D9B00, SL_AddRefToString, PATCH_JUMP);
	call(0x4F1500, SL_RemoveRefToStringOfSize, PATCH_JUMP);
	call(0x47CD70, SL_RemoveRefToString, PATCH_JUMP);
	call(0x417730, Scr_SetString, PATCH_JUMP);
	call(0x4401E0, SL_GetStringLen, PATCH_JUMP);
	call(0x40C050, SL_TransferRefToUser, PATCH_JUMP);
	call(0x4B4310, SL_AddUser, PATCH_JUMP);
	call(0x430510, SL_ConvertToLowercase, PATCH_JUMP);
	call(0x4F46D0, SL_ShutdownSystem, PATCH_JUMP);
	call(0x4A44A0, SL_TransferSystem, PATCH_JUMP);

	stringHeap = HeapCreate(0, 1024 * 1024, 0);

	// path_node_constant_t marking function; has some terrible string references
	*(BYTE*)0x4F74B0 = 0xC3;
}
int SL_GetStringOfSize(const char* string, int system, int size)
{
	EnterCriticalSection(&slCritSec);

	// try to find the string first
	std::string str(string, size);
	google::dense_hash_map<std::string, uint16_t>::const_iterator iter = slHashMap.find(str);

	if (iter != slHashMap.end())
	{
		SL_Debug("GetStringOfSize '%s' found %i\n", string, iter->second);

		SL_AddRefToString(iter->second);

		LeaveCriticalSection(&slCritSec);
		return iter->second;
	}

	// add the string to the list
	ScriptStringData* data = &slStrings[slFirstFree];
	uint16_t stringID = slFirstFree;

	//data->data = new ScriptStringManagementData;
	data->data = (ScriptStringManagementData*)HeapAlloc(stringHeap, 0, sizeof(ScriptStringManagementData));
	//data->string = (char*)malloc(size);
	data->string = (char*)HeapAlloc(stringHeap, 0, size);
	memcpy(data->string, string, size);

	data->length = size;

	data->data->data = data;
	data->data->references = 1;
	data->data->users = system;

	// find the next free string
	for (int i = slFirstFree; i < MAX_SCRIPT_STRINGS; i++)
	{
		if (!slStrings[i].string)
		{
			slFirstFree = i;
			break;
		}
	}

	slHashMap[str] = stringID;

	LeaveCriticalSection(&slCritSec);

	SL_Debug("GetStringOfSize '%s' allocated %i (user %i)\n", string, stringID, system);

	return stringID;
}
Пример #5
0
/*!
	initialise the various google::dense_hash_map "lists" that are used throughout QTils
 */
void init_QTMWlists()
{
	if( !q2nw_initialised ){
		// these two keys (variable names) should never occur:
		qtwmh2hwnd.set_empty_key( (QTMovieWindowH) 0 );
		qtwmh2hwnd.set_deleted_key( (QTMovieWindowH) -1 );
		q2nw_initialised = 1;
	}
	if( !nw2q_initialised ){
		// these two keys (variable names) should never occur:
		hwnd2qtwmh.set_empty_key( (NativeWindow) 0 );
		hwnd2qtwmh.set_deleted_key( (NativeWindow) -1 );
		nw2q_initialised = 1;
	}
	if( !m2qtmwh_initialised ){
		// these two keys (variable names) should never occur:
		m2qtmwh.set_empty_key( (Movie) 0 );
		m2qtmwh.set_deleted_key( (Movie) -1 );
		m2qtmwh_initialised = 1;
	}
#if defined(WIN32) || defined(_WINDOWS) || defined(_MSC_VER)
	if( !met_initialised ){
	  int i;
		// these two keys (variable names) should never occur:
		metMap.set_empty_key( (ErrCode) 65535 );
		metMap.set_deleted_key( (ErrCode) -65535 );
		for( i = 0 ; i < sizeof(macErrorTable) / sizeof(MacErrorTables) ; i++ ){
			metMap[macErrorTable[i].errCode] = &macErrorTable[i];
		}
		met_initialised = 1;
	}
#endif
	lastQTWMH = NULL;
}
void SL_FreeString(uint16_t string)
{
	EnterCriticalSection(&slCritSec);

	ScriptStringData* data = &slStrings[string];
	//delete data->data;
	HeapFree(stringHeap, 0, data->data);

	std::string str(data->string, data->length);

	slHashMap.erase(str);

	SL_Debug("FreeString %i '%s'\n", string, data->string);

	//free((void*)data->string);
	HeapFree(stringHeap, 0, data->string);

	if (string < slFirstFree)
	{
		slFirstFree = string;
	}

	data->data = NULL;
	data->string = NULL;

	LeaveCriticalSection(&slCritSec);
}
// entry point
void PatchMW2_StringTable()
{
	stringTables.set_empty_key("");

	stringTableHook.initialize(stringTableHookLoc, StringTable_GetAsset);
	stringTableHook.installHook();
}
const char* SEH_GetLocalizedString(const char* key)
{
	google::dense_hash_map<std::string, std::string>::const_iterator iter = _localizedStrings.find(key);
 
	if (iter != _localizedStrings.end())
	{
		return (*iter).second.c_str();
	}
 
	localizedEntry_s* entry = (localizedEntry_s*)DB_FindXAssetHeader(ASSET_TYPE_LOCALIZE, key);
 
	if (entry)
	{
		return entry->value;
	}
	
	return NULL;
}
Пример #9
0
void dump_results(google::dense_hash_map<std::string, Probe*> &h_probes)
{
  int cs1[5], cs2[5];
  Probe *op; // Original probe

  google::dense_hash_map<std::string, Probe *>::iterator p_iter;
  for (p_iter=h_probes.begin(); p_iter!=h_probes.end(); p_iter++) {
    // In op we want always the original probe, not the rc one
    op = p_iter->second->is_a_rc_probe ? p_iter->second->rc : p_iter->second;
    if (!op->visited && (op->has_hits() || op->rc->has_hits())) {
      op->get_counters(cs1);
      op->rc->get_counters(cs2);
      std::cout
        << op->get_chrm() << ","
        << op->get_coordinates() <<  ","
        << op->get_id() <<  ","
        << op->get_ref() <<  ","
        << op->get_var() <<  ","

        << cs1[0] << ","
        << cs1[1] << ","
        << cs1[2] << ","
        << cs1[3] << ","
        << cs1[4] << ","

        << cs2[0] << ","
        << cs2[1] << ","
        << cs2[2] << ","
        << cs2[3] << ","
        << cs2[4] << ","

        << cs1[0] + cs2[0] << ","
        << cs1[1] + cs2[1] << ","
        << cs1[2] + cs2[2] << ","
        << cs1[3] + cs2[3] << ","
        << cs1[4] + cs2[4]

        << std::endl;

      op->visited = 1;
      op->rc->visited = 1;
    }
  }
}
Пример #10
0
/*!
	given a movie, find the associated QTMovieWindowH object
 */
QTMovieWindowH QTMovieWindowH_from_Movie( Movie movie )
{ QTMovieWindowH wi;
	if( movie && m2qtmwh_initialised && m2qtmwh.count(movie) ){
		wi = m2qtmwh[movie];
		if( Handle_Check(wi) && (*wi)->self == *wi && (*wi)->theMovie == movie ){
			return wi;
		}
	}
	return NULL;
}
Пример #11
0
/*!
	look up the QTMovieWindowH that uses the given window for displaying. Used in event processing.
 */
QTMovieWindowH QTMovieWindowH_from_NativeWindow( NativeWindow hwnd )
{ QTMovieWindowH wi;
	if( hwnd2qtwmh.count(hwnd) ){
		wi = hwnd2qtwmh[hwnd];
		if( QTMovieWindowH_Check(wi) && (*wi)->theView == hwnd ){
			return wi;
		}
	}
	return NULL;
}
Пример #12
0
 // fetch the row associated with the given index 
 // and assign it if it doesn't exist
 lindex fetch_index(mwIndex gi) {
     if (imap.count(gi) != 0) {
         return imap[gi];
     }
     lindex li = nextind;
     nextind ++;
     imap[gi] = li;
     grow_vector_to_index(gmap, li, (mwIndex)(-1));
     gmap[li] = gi;
     return li;
 }
void PatchMW2_LocalizedStrings()
{
	_localizedStrings.set_empty_key("");
 
	loadLocalizeHook.initialize(loadLocalizeHookLoc, SEH_GetLocalizedString);
	loadLocalizeHook.installHook();
 
	call(0x4CE5EE, SetString, PATCH_CALL); //instead of calling CStringEdPackage::SetString in CStringEdPackage::ParseLine we call our SetString
	call(0x41D860, SELoadLanguageHookStub, PATCH_JUMP); //instead of the game loading str files according to loc_language we load them according to loc_modlanguage
 
	Dvar_RegisterEnum("loc_modLanguage", ModLanguageEnum, 0, DVAR_FLAG_SAVED, "Preferred language for custom localized strings.");
}
int FindStringOfSize(const char* string, int size)
{
	EnterCriticalSection(&slCritSec);

	std::string str(string, size);

	google::dense_hash_map<std::string, uint16_t>::const_iterator iter = slHashMap.find(str);

	if (iter != slHashMap.end())
	{
		LeaveCriticalSection(&slCritSec);

		SL_Debug("FindStringOfSize '%s' found %i\n", string, iter->second);

		return iter->second;
	}

	SL_Debug("FindStringOfSize '%s' - no results!\n", string, iter->second);

	LeaveCriticalSection(&slCritSec);

	return 0;
}
Пример #15
0
 virtual void SetUp() {
     hashMap.set_empty_key(NULL);
     hashMap["january"] = 31;
     hashMap["february"] = 29;
     hashMap["march"] = 31;
     hashMap["april"] = 30;
     hashMap["may"] = 31;
     hashMap["june"] = 30;
     hashMap["july"] = 31;
     hashMap["august"] = 31;
     hashMap["september"] = 30;
     hashMap["october"] = 31;
     hashMap["november"] = 30;
     hashMap["december"] = 31;
 }
Пример #16
0
const char *GetMacOSStatusErrStrings(ErrCode err, const char **comment)
{
#if defined(WIN32) || defined(_WINDOWS) || defined(_MSC_VER)
  MacErrorTables *et;
	if( met_initialised && metMap.count(err) ){
		if( (et = metMap[err]) ){
			if( comment ){
				*comment = et->errComment;
			}
			return et->errString;
		}
	}
	return NULL;
#else
	if( comment ){
		*comment = GetMacOSStatusCommentString(err);
	}
	return GetMacOSStatusErrorString(err);
#endif
}
Пример #17
0
/*!
	unregisters a QTMovieWindowH object
 */
void unregister_QTMovieWindowH( QTMovieWindowH qtwmH )
{ NativeWindow hwnd;
	if( qtwmH && q2nw_initialised && qtwmh2hwnd.count(qtwmH) ){
		hwnd = qtwmh2hwnd[qtwmH];
		if( (*qtwmH)->theView == hwnd ){
			if( nw2q_initialised && hwnd2qtwmh.count(hwnd) ){
				hwnd2qtwmh.erase(hwnd);
				hwnd2qtwmh.resize(0);
			}
		}
		qtwmh2hwnd.erase(qtwmH);
		qtwmh2hwnd.resize(0);
		if( lastQTWMH == qtwmH ){
			lastQTWMH = NULL;
		}
	}
}
Пример #18
0
    local_stochastic_graph_exponential(
            sparserow* G_, 
            const double t_, double eps_,
            size_t maxpush_) 
	: G(G_), t(t_), eps(eps_), maxpush(maxpush_), 
            n(G->n), N(taylordegree(t, eps)),
            pushcoeff(N+1,0.), sval(std::numeric_limits<lindex>::max()),
            nextind(0), noffset(0),
            lneigh(nstart, sval), 
            lp(nstart, std::make_pair(sval, sval)), 
            gmap(nstart, (mwIndex)-1), npush(0)
    {        
        DEBUGPRINT(("gsqres interior: t=%lf eps=%lf \n", t, eps));
        DEBUGPRINT(("gsqres: n=%i N=%i \n", n, N));
        
        // initialize the weights for the different residual partitions
        //  into the vector "pushcoeff"
        std::vector<double> psivec(N+1,0.);
        psivec[N] = 1;
        for (lindex k = 1; k <= N ; k++){
            psivec[N-k] = psivec[N-k+1]*t/(double)(N-k+1) + 1;
        } // psivec[k] = psi_k(t)

        pushcoeff[0] = ((exp(t)*eps)/(double)N)/psivec[0];
        // This is a more numerically stable way to compute
        //      pushcoeff[j] = exp(t)*eps/(n*N*psivec[j])
        for (lindex k = 1; k <= N ; k++){
            pushcoeff[k] = pushcoeff[k-1]*(psivec[k-1]/psivec[k]);
        }
        
        if (n > std::numeric_limits<lindex>::max()) {
            mexErrMsgIdAndTxt("gexpmq_mex:unimplemented", 
                    "support only up to %i elements", 
                    std::numeric_limits<lindex>::max());
        }
        
        imap.set_empty_key(sval);        
    }
Пример #19
0
/*!
	find the native window in which a QTMovieWindowH object is displayed.
	This exists mostly for double-check reasons, as the window is also accessible as
	(*qtwmH)->theView
 */
NativeWindow NativeWindow_from_QTMovieWindowH( QTMovieWindowH qtwmH )
{ NativeWindow hwnd;
	if( qtwmH && q2nw_initialised ){
		// some caching to speed things up ...
		if( qtwmH == lastQTWMH && (*lastQTWMH)->theView ){
			return (*lastQTWMH)->theView;
		}
		else if( qtwmh2hwnd.count(qtwmH) ){
			hwnd = qtwmh2hwnd[qtwmH];
			if( (*qtwmH)->theView == hwnd ){
				lastQTWMH = qtwmH;
				return hwnd;
			}
			else if( !(*qtwmH)->theView ){
				// 20110228: a window that has been closed through the GUI but not yet
				// completely flushed from our management. We will need to suppose that
				// it was once a valid window, and thus cannot return NULL.
				return hwnd;
			}
		}
	}
	return NULL;
}
void SELoadLanguageHookStub()
{
	_localizedStrings.clear();
 
	//get language from loc_modLanguage
	dvar_t* modLang = Dvar_FindVar("loc_modLanguage");
	char** enumList = *(char***)&(modLang->max); //not sure if this is really dvar_maxmin_t max.
	char* language = enumList[modLang->current.integer];
 
	//'official' iw4m localized strings
	isW2Strings = true;
	SE_Load("localizedstrings/w2.str", 0);
	isW2Strings = false;
 
	if(LoadStrFiles(language)==0)
		LoadStrFiles("english");//load english str files if there aren't any of selected language
 
	__asm
	{
		leave
		mov eax, 0x41D885 //back to SE_LoadLanguage
		jmp eax
	}
}
Пример #21
0
 void assertThatHashMapHasCorrectValues(std::vector<char*> elements) {
     for (int i = 0; i < elements.size(); i += 2) {
         ASSERT_FALSE(hashMap.find(elements[i]) == hashMap.end());
         ASSERT_EQ(hashMap[elements[i]], atoi(elements[i + 1]));
     }
 }
Пример #22
0
 void assertHashMapSizeEqualTo(int count) {
     ASSERT_FALSE(hashMap.empty());
     ASSERT_EQ(count, hashMap.size());
 }
Пример #23
0
 void assertThatHashMapHasKeys(std::vector<char*> elements) {
     for (int i = 0; i < elements.size(); ++i) {
        ASSERT_FALSE(hashMap.find(elements[i]) == hashMap.end());
     }
 }
Пример #24
0
 void assertThatHashMapIsEmpty() {
     ASSERT_TRUE(hashMap.empty());
     ASSERT_EQ(0, hashMap.size());
 }