Exemple #1
0
void serverProcessReplacement(unsigned int timeDelta) 
{
	unsigned int servertickaddr=0x602350;
	unsigned int serverthisptr=0x9E5EC0;

	for (auto it = sServerProcessResponders.begin(); it != sServerProcessResponders.end(); it++)
		(*it)(timeDelta);

	__asm 
	{
		mov ecx,serverthisptr
		push timeDelta
		call servertickaddr
	}
	
	return;

}
Exemple #2
0
vector<bool> wordBreak1(string s, std::tr1::unordered_set<string> &dict) {
       vector<bool> wordB(s.length()+1,false);       //wordB stands for the string from 0 to i can be segument

        wordB[0]=true;
        for(int i=1;i<s.length()+1;i++)
        {
            for(int j=i-1;j>=0;j--)
            {
                if(wordB[j]&&dict.find(s.substr(j,i-j))!=dict.end())
                    {
                        wordB[i]=true;
                        break;
                    }
            }
        }
        return wordB;


}
Exemple #3
0
inline std::tr1::unordered_set<T>& operator>> (object o, std::tr1::unordered_set<T>& v)
{
	if(o.type != type::ARRAY) { throw type_error(); }
	object* p = o.via.array.ptr + o.via.array.size;
	object* const pbegin = o.via.array.ptr;
	while(p > pbegin) {
		--p;
		v.insert(p->as<T>());
	}
	return v;
}
Exemple #4
0
// Mod Loader Implementation
bool conLoadMod(Linker::SimObject *obj,S32 argc, const char* argv[])
{
		typedef void (*LPMODINIT)(void);
		HINSTANCE hDLL = NULL;
		LPMODINIT lpInitMod = NULL;

		std::string raw = "mods\\";
		raw += argv[1];
		raw += ".dll";

		std::wstring modification(raw.begin(), raw.end());

		hDLL = LoadLibrary(modification.c_str());
		if (hDLL == NULL)
		{
			Con::errorf(0, "loadMod(): Failed to load DLL '%s'. Does it exist in GameData\\mods? (%u)", raw.c_str(), GetLastError());
			return false; // The DLL doesn't exist
		}
		
		lpInitMod = (LPMODINIT)GetProcAddress(hDLL, "ModInitialize"); // Attempt to load our entry point

		if (lpInitMod == NULL)
		{
			Con::errorf(0, "loadMod(): Failed to locate entry point 'ModInitialize' in mod DLL '%s'. Is it a good mod DLL? (%u)", raw.c_str(), GetLastError());
			return false; // Unable to load entry point
		}

		lpInitMod();
		Con::errorf(0, "loadMod(): Loaded and executed entry point code for mod DLL '%s'", raw.c_str());

		// Check if there's a server process responder in this DLL
		ServerProcessPointer serverProcess = (ServerProcessPointer)GetProcAddress(hDLL, "ServerProcess"); // Attempt to load our entry point

		if (serverProcess != NULL)
		{
			sServerProcessResponders.insert(sServerProcessResponders.end(), serverProcess);
			Con::errorf(0, "loadMod(): Added server process responder for mod");
		}

		return true;
}
Exemple #5
0
void dfs(int start,int n,string s,string cur,std::tr1::unordered_set<string> &dict,vector<bool> wordB)
{
    if(start==n)
    {
        result.push_back(cur);
        return ;
    }
    for(int i=start;i<n;i++)
    {
        string t=s.substr(start,i+1-start);
        if(wordB[i+1]&&dict.find(t)!=dict.end())
        {
            int c=cur.size();//used to record the current element ,will be used to keep the size like the pop operation,all is caused by " "signal
            cur+=t;
            if(i<n-1)
            cur.push_back(' ');//the last element do not need to add a space symbol
            dfs(i+1,n,s,cur,dict,wordB);
            cur.resize(c);//being used to back to the previous condition
        }
    }
}
void QuadTreeNode::GetOccupants(std::tr1::unordered_set<QuadTreeOccupant*> &upperOccupants, QuadTreeNode* newNode)
{
	// Assign the new node pointers while adding the occupants to the upper node
	for(std::tr1::unordered_set<QuadTreeOccupant*>::iterator it = occupants.begin(); it != occupants.end(); it++)
	{
		(*it)->pQuadTreeNode = newNode;
		upperOccupants.insert(*it);
	}

	// Recusively go through children if there are any
	if(hasChildren)
		for(unsigned int x = 0; x < 2; x++)
			for(unsigned int y = 0; y < 2; y++)
				children[x][y]->GetOccupants(upperOccupants, newNode);
}
Exemple #7
0
inline bool operator==(const std::tr1::unordered_set<size_t> &a, const std::tr1::unordered_set<size_t> &b) {
  if (a.size() != b.size()) return false;

  std::tr1::unordered_set<size_t>::const_iterator cit = a.begin();
  while (a.end() != cit) {
    if (b.end() == b.find(*cit))
      return false;
    cit++;
  }
 
  return true;
}
Exemple #8
0
void outputDiskCombinedGauges(int gtype, const merged_gauge_map_t& prev, const merged_gauge_map_t& gauges,
			      bool& first, const std::tr1::unordered_set<int>& diskIds)
{
	for (std::tr1::unordered_set<int>::const_iterator idIter = diskIds.begin(); idIter != diskIds.end(); ++idIter) {
		local_key_set_t keys;

		for (const_gauge_iterator iter = gauges.begin(); iter != gauges.end(); ++iter) {
			if (IID_IS4DISK(iter->first.sid.iid) && IID2DISKNO(iter->first.sid.iid)== *idIter) {
				local_key_t key = iter->first;
				key.sid.iid = 0;

				keys.insert(key);
			}
		}

		
		for (local_key_set_t::iterator iter = keys.begin(); iter != keys.end(); ++iter) {
			if (first) first = false; else printf(",");
			if (gtype == GT_PRODUCT) {
				// {pid,mid=0,usr|sys|idl|wt,host=0}
				printf("{\"gtype\":\"P\",\"pid\":%d,\"type\":\"disk\"", iter->sid.pid);
			}
			else if (gtype == GT_MODULE) {
				// {pid,mid,usr|sys|idl|wt,host=0}
				printf("{\"gtype\":\"M\",\"pid\":%d,\"mid\":%d,\"type\":\"disk\"", iter->sid.pid, iter->sid.mid);
			}
			else if (gtype == GT_HOST) {
				// {pid=0,mid=0,usr|sys|idl|wt,host}
				// TODO: host-name, ip6
				char buf[128];
				if (iter->hip.ver == 4) inet_ntop(AF_INET, &iter->hip.ip.ip4, buf, sizeof buf);
				else if (iter->hip.ver == 6) inet_ntop(AF_INET6, &iter->hip.ip.ip6[0], buf, sizeof buf);
				printf("{\"gtype\":\"H\",\"ip\":\"%s\",\"host\":\"%s\",\"type\":\"disk\"", buf, buf);
			}

			printf(",\"name\":\"disk-%d\"", *idIter);
		
			int64_t rCalls = 0, rBytes = 0, wCalls = 0, wBytes = 0;
			local_key_t key = *iter; 

			key.sid.iid = IID_DISK(*idIter, DISK_T_R_CALLS);
			const_gauge_iterator iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				rCalls = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_DISK(*idIter, DISK_T_R_BYTES);
			iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				rBytes = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_DISK(*idIter, DISK_T_W_CALLS);
			iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				wCalls = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_NET(*idIter, DISK_T_W_BYTES);
			iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				wBytes = iter2->second.gval - iter1->second.gval;

			printf(",\"values\":{\"r-calls\":%ld,\"r-bytes\":%ld,\"w-calls\":%ld,\"w-bytes\":%ld}}", rCalls, rBytes, wCalls, wBytes);
		}
	}

	return;
}
Exemple #9
0
void outputNetCombinedGauges(int gtype, const merged_gauge_map_t& prev, const merged_gauge_map_t& gauges,
			     bool& first, const std::tr1::unordered_set<int>& netIds)
{
	for (std::tr1::unordered_set<int>::const_iterator idIter = netIds.begin(); idIter != netIds.end(); ++idIter) {
		local_key_set_t keys;

		for (const_gauge_iterator iter = gauges.begin(); iter != gauges.end(); ++iter) {
			if (IID_IS4NET(iter->first.sid.iid) && IID2NETNO(iter->first.sid.iid) == *idIter) {
				local_key_t key = iter->first;
				key.sid.iid = 0;
				
				keys.insert(key);
			}
		}

		
		for (local_key_set_t::iterator iter = keys.begin(); iter != keys.end(); ++iter) {
			if (first) first = false; else printf(",");
			if (gtype == GT_PRODUCT) {
				// {pid,mid=0,usr|sys|idl|wt,host=0}
				printf("{\"gtype\":\"P\",\"pid\":%d,\"type\":\"net\"", iter->sid.pid);
			}
			else if (gtype == GT_MODULE) {
				// {pid,mid,usr|sys|idl|wt,host=0}
				printf("{\"gtype\":\"M\",\"pid\":%d,\"mid\":%d", iter->sid.pid, iter->sid.mid);
			}
			else if (gtype == GT_HOST) {
				// {pid=0,mid=0,usr|sys|idl|wt,host}
				// TODO: host-name, ip6
				char buf[128];
				if (iter->hip.ver == 4) inet_ntop(AF_INET, &iter->hip.ip.ip4, buf, sizeof buf);
				else if (iter->hip.ver == 6) inet_ntop(AF_INET6, &iter->hip.ip.ip6[0], buf, sizeof buf);
				printf("{\"gtype\":\"H\",\"ip\":\"%s\",\"host\":\"%s\"", buf, buf);
			}

			// TODO: get its name
			printf(",\"name\":\"net-%d\"", *idIter);
		
			int64_t inBytes = 0, inPkts = 0, outBytes = 0, outPkts = 0;
			local_key_t key = *iter; 

			key.sid.iid = IID_NET(*idIter, NET_T_IN_BYTES);
			const_gauge_iterator iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				inBytes = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_NET(*idIter, NET_T_IN_PKTS);
			iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				inPkts = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_NET(*idIter, NET_T_OUT_BYTES);
			iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				outBytes = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_NET(*idIter, NET_T_OUT_PKTS);
			iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				outPkts = iter2->second.gval - iter1->second.gval;

			printf(",\"values\":{\"ib\":%ld,\"ip\":%ld,\"ob\":%ld,\"op\":%ld}}", inBytes,inPkts,outBytes,outPkts);
		}
	}

	return;
}
Exemple #10
0
static void outputCpuCombinedGauges(int gtype, const merged_gauge_map_t& prev, const merged_gauge_map_t& gauges,
				    bool& first, std::tr1::unordered_set<int> cpuIds)
{
	for (std::tr1::unordered_set<int>::const_iterator idIter = cpuIds.begin(); idIter != cpuIds.end(); ++idIter) {
		local_key_set_t keys;

		for (const_gauge_iterator iter = gauges.begin(); iter != gauges.end(); ++iter) {
			if (IID_IS4CPU(iter->first.sid.iid) && IID2CPUNO(iter->first.sid.iid) == *idIter) {
				local_key_t key = iter->first;
				key.sid.iid = 0;

				keys.insert(key);
			}
		}

		for (local_key_set_t::iterator iter = keys.begin(); iter != keys.end(); ++iter) {
			if (first) first = false; else printf(",");
			if (gtype == GT_PRODUCT) {
				// {pid,mid=0,usr|sys|idl|wt,host=0}
				printf("{\"gtype\":\"P\",\"pid\":%d,\"type\":\"cpu\"", iter->sid.pid);
			}
			else if (gtype == GT_MODULE) {
				// {pid,mid,usr|sys|idl|wt,host=0}
				printf("{\"gtype\":\"M\",\"pid\":%d,\"mid\":%d", iter->sid.pid, iter->sid.mid);
			}
			else if (gtype == GT_HOST) {
				// {pid=0,mid=0,usr|sys|idl|wt,host}
				// TODO: host-name, and support ip6
				char buf[128];
				if (iter->hip.ver == 4) inet_ntop(AF_INET, &iter->hip.ip.ip4, buf, sizeof buf);
				else if (iter->hip.ver == 6) inet_ntop(AF_INET6, &iter->hip.ip.ip6[0], buf, sizeof buf);
				printf("{\"gtype\":\"H\",\"ip\":\"%s\",\"host\":\"%s\"", buf, buf);
			}

			if (*idIter == IID_CPU_TOTAL) printf(",\"name\":\"cpu\"");
			else printf(",\"name\":\"cpu-%d\"", *idIter);
		
			local_key_t key = *iter; 
			key.sid.iid = IID_CPU(*idIter, CPU_USR);
			int64_t usr = -1, sys = -1, idl = -1, wt = -1;
			const_gauge_iterator iter1 = prev.find(key), iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				usr = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_CPU(*idIter, CPU_SYS);
			iter1 = prev.find(key); iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				sys = iter2->second.gval - iter1->second.gval;

			key.sid.iid = IID_CPU(*idIter, CPU_IDL);
			iter1 = prev.find(key); iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				idl = iter2->second.gval - iter1->second.gval;
			
			key.sid.iid = IID_CPU(*idIter, CPU_WT);
			iter1 = prev.find(key); iter2 = gauges.find(key);
			if (iter1 != prev.end() && iter2 != gauges.end())
				wt = iter2->second.gval - iter1->second.gval;

			if (usr == -1 || sys == -1 || idl == -1 || wt == -1) {
				printf(",\"values\":{}}");
			}
			else {
				// TODO: change to percent
				//int total = usr + sys + idl + wt;
				//int all = spanLength(spanUnit, spanCount) / 1000 * 100;
				//if (all % 100
				
				printf(",\"values\":{\"usr\":%ld,\"sys\":%ld,\"idl\":%ld,\"wt\":%ld}}", usr,sys,idl,wt);
			}
		}
	}
}
Exemple #11
-1
inline void operator<< (object::with_zone& o, const std::tr1::unordered_set<T>& v)
{
	o.type = type::ARRAY;
	if(v.empty()) {
		o.via.array.ptr = NULL;
		o.via.array.size = 0;
	} else {
		object* p = (object*)o.zone->malloc(sizeof(object)*v.size());
		object* const pend = p + v.size();
		o.via.array.ptr = p;
		o.via.array.size = v.size();
		typename std::tr1::unordered_set<T>::const_iterator it(v.begin());
		do {
			*p = object(*it, o.zone);
			++p;
			++it;
		} while(p < pend);
	}
}