Exemplo n.º 1
0
// ClientCDKey::CreateSymmetricKey
// Creates a symmetric key from product name used to save/load CD-Key to/from
// the registry.  Symmetric key is created via a series of CRCs on the product.
void
ClientCDKey::CreateSymmetricKey(BFSymmetricKey& theSymKeyR) const
{
	WTRACE("ClientCDKey::CreateSymmetricKey");
	WDBG_LL("ClientCDKey::CreateSymmetricKey from product=" << mProduct);
	CRC16     aCRC;
	RawBuffer aBuf;

	// CRC the product and use it as 1st 2 bytes of key
	aCRC.Put(mProduct);
	unsigned short aCheckSum = aCRC.GetCRC();
	WDBG_LL("ClientCDKey::CreateSymmetricKey First CRC=" << aCheckSum);
	aBuf.assign(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum));

	// CRC each of 1st 3 chars of product and add them to key.
	for (int i=0; (i < 3) && (i < mProduct.size()); i++)
	{
		aCRC.Put(static_cast<unsigned char>(mProduct[i]));
		aCheckSum = aCRC.GetCRC();
		WDBG_LL("ClientCDKey::CreateSymmetricKey Add CRC=" << aCheckSum);
		aBuf.append(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum));
	}

	// Create the key
	WDBG_LL("ClientCDKey::CreateSymmetricKey Buf=" << aBuf);
	theSymKeyR.Create(aBuf.size(), aBuf.data());
}
Exemplo n.º 2
0
/********************************************************************************
 * Subscribe to the game list in the current chat room							*
 ********************************************************************************/
void CChatView::SubscribeDataObjectCallback(const WONAPI::RoutingServerClient::ReadDataObjectResult& theResultR, CChatView* pThat)
{
	// Check the result from SubscribeDataObject	
	switch (theResultR.mStatus)
	{
		case StatusCommon_Success:
			{
			// List retrieved
			pThat->DisplayText("<System> Subscribed to game list successfully\r\n");

			for (std::list<RoutingServerClient::DataObject>::const_iterator itr = theResultR.mDataObjectList.begin(); itr != theResultR.mDataObjectList.end(); itr++)
			{
				// Store the games in our GameMap
				string gamename = (char*)itr->mDataType.data() + OBJ_GAMEPREFIX.size();
				((CWhiteBoardDoc*)pThat->GetDocument())->mGameMap[gamename] = *itr; 
			}
			break;
			}
		case StatusRouting_SubscriptionAlreadyExists:
			pThat->DisplayText("<System> ***ERROR Attemp to subscribe twice***\r\n");
			break;
		default:
			pThat->DisplayText("<System> ***ERROR Failed to retrieve game list***\r\n");
			break;
	}
};
Exemplo n.º 3
0
KeyAESImpl::KeyAESImpl(const RawBuffer &buf) : m_key(buf)
{
    // buf stores bytes -> compare the bit sizes
    switch (buf.size() * 8) {
    case 128:
    case 192:
    case 256:
        break;

    default:
        throw std::invalid_argument("invalid AES key size");
    }
}
Exemplo n.º 4
0
void Matchmaker::GetTitanServerList()
{
#ifdef DLLSAMPLE
	mNewAuthServers.clear();
	mNewContestServers.clear();
	mNewEventServers.clear();
	mNewFirewallServers.clear();
	mNewProfileServers.clear();
	
	HWONDATAOBJECT aDataObjectH = WONDataObjectCreate(OBJ_VALIDVERSIONS.c_str(), OBJ_VALIDVERSIONS.size(), NULL, 0);
	WONError aError = WONDirGetDirectoryW(NULL, mDirServers, mNumDirServers,
	                                      DIR_TITANSERVER, NULL, NULL,
	                                      WONDir_GF_DECOMPROOT | WONDir_GF_DECOMPRECURSIVE | WONDir_GF_DECOMPSERVICES | WONDir_GF_ADDTYPE | WONDir_GF_SERVADDNAME | WONDir_GF_SERVADDNETADDR | WONDir_GF_ADDDOTYPE | WONDir_GF_ADDDODATA,
	                                      &aDataObjectH, 1, TitanServerEntityCallback, this, gRequestTimeout);

	CopySTLAddressListToArray(mNewAuthServers,     &mAuthServers,     &mNumAuthServers);
	CopySTLAddressListToArray(mNewContestServers,  &mContestServers,  &mNumContestServers);
	CopySTLAddressListToArray(mNewEventServers,    &mEventServers,    &mNumEventServers);
	CopySTLAddressListToArray(mNewFirewallServers, &mFirewallServers, &mNumFirewallServers);
	CopySTLAddressListToArray(mNewProfileServers,  &mProfileServers,  &mNumProfileServers);
#else
	DataObjectTypeSet aDataObjectSet;
	aDataObjectSet.insert(WONCommon::DataObject(OBJ_VALIDVERSIONS));
	WONMsg::DirEntityList entityList;
	Error aError = GetDirectory(NULL, // no identity needed to get TitanServers (after all, the AuthServers are listed in there)
								mDirServers, mNumDirServers,
								NULL,
								DIR_TITANSERVER, 
								&entityList,
								WONMsg::GF_DECOMPROOT | WONMsg::GF_DECOMPRECURSIVE | WONMsg::GF_DECOMPSERVICES | WONMsg::GF_ADDTYPE | WONMsg::GF_SERVADDNAME | WONMsg::GF_SERVADDNETADDR | WONMsg::GF_ADDDOTYPE | WONMsg::GF_ADDDODATA,
								aDataObjectSet,
								0, 0,
								gRequestTimeout);

	switch(aError) 
	{
		case Error_Success:
		{
			delete[] mAuthServers; mNumAuthServers = 0;
			mAuthServers = new IPSocket::Address[entityList.size()];
			delete[] mContestServers; mNumContestServers = 0;
			mContestServers = new IPSocket::Address[entityList.size()];
			delete[] mEventServers; mNumEventServers = 0;
			mEventServers = new IPSocket::Address[entityList.size()];
			delete[] mFirewallServers; mNumFirewallServers = 0;
			mFirewallServers = new IPSocket::Address[entityList.size()];
			delete[] mProfileServers; mNumProfileServers = 0;
			mProfileServers = new IPSocket::Address[entityList.size()];

			DirEntityList::const_iterator aDirEntityListItr = entityList.begin();
			for( ; aDirEntityListItr != entityList.end(); ++aDirEntityListItr)
			{
				if (aDirEntityListItr->mType == WONMsg::DirEntity::ET_DIRECTORY)
				{
					DataObjectTypeSet::const_iterator aDataObjectSetItr = aDirEntityListItr->mDataObjects.begin();
					for( ; aDataObjectSetItr != aDirEntityListItr->mDataObjects.end(); ++aDataObjectSetItr)
					{
						if (aDataObjectSetItr->GetDataType() == OBJ_VALIDVERSIONS)
							mValidVersions = reinterpret_cast<const char*>(aDataObjectSetItr->GetData().c_str());
					}
				}
				else if (aDirEntityListItr->mName == SERVERNAME_AUTH)
					mAuthServers[mNumAuthServers++] = IPSocket::Address(*aDirEntityListItr);
				else if (aDirEntityListItr->mName == SERVERNAME_CONTEST)
					mContestServers[mNumContestServers++] = IPSocket::Address(*aDirEntityListItr);
				else if (aDirEntityListItr->mName == SERVERNAME_EVENT)
					mEventServers[mNumEventServers++] = IPSocket::Address(*aDirEntityListItr);
				else if (aDirEntityListItr->mName == SERVERNAME_FIREWALL)
					mFirewallServers[mNumFirewallServers++] = IPSocket::Address(*aDirEntityListItr);
				else if (aDirEntityListItr->mName == SERVERNAME_PROFILE)
					mProfileServers[mNumProfileServers++] = IPSocket::Address(*aDirEntityListItr);
			}
			break;
		}

		case StatusDir_DirNotFound:
			OutputError("Directory containing Titan servers not found");
			break;
		default:
			OutputError("Failed to get list of Titan servers!", aError);
			break;
	}
#endif // DLLSAMPLE
}
Exemplo n.º 5
0
  /** original mesh file format.

	char[3]           "MSH"
	uint8_t           mesh count.
	reserved          (2 byte)
	uint32_t          vbo offset by the top of file(32bit alignment).
	uint32_t          vbo byte size(32bit alignment).
	uint32_t          ibo byte size(32bit alignment).

	[
	  uint8_t         mesh name length.
	  char[mesh name length] mesh name(without zero ternmination).
	  uint8_t         material count.
	  padding         (4 - (length + 2) % 4) % 4 byte.
	  [
		uint32_t        ibo offset.
		uint16_t        ibo size(this is the polygon counts, so actual ibo size is 3 times).
		uint8_t         red
		uint8_t         green
		uint8_t         blue
		uint8_t         alpha
		uint8_t         metallic
		uint8_t         roughness
		] x (ibo count)
	] x (mesh count)

	uint8_t                          albedo texture name length.
	char[albedo texture name length] albedo texture name(without zero ternmination).
	uint8_t                          normal texture name length.
	char[normal texture name length] normal texture name(without zero ternmination).
	padding                          (4 - (texture name block size % 4) % 4 byte.

	vbo               vbo data.
	ibo               ibo data.
	padding           (4 - (ibo byte size % 4) % 4 byte.

	uint16_t          bone count.
	uint16_t          animation count.

	[
	  RotTrans        rotation and translation for the bind pose.
	  int32_t         parent bone index.
	] x (bone count)

	[
	  uint8_t         animation name length.
	  char[24]        animation name.
	  bool            loop flag
	  uint16_t        key frame count.
	  float           total time.
	  [
		float         time.
		[
		  RotTrans    rotation and translation.
		] x (bone count)
	  ] x (key frame count)
	] x (animation count)
  */
  ImportMeshResult ImportMesh(const RawBuffer& data, GLuint& vbo, GLintptr& vboEnd, GLuint& ibo, GLintptr& iboEnd)
  {
	const uint8_t* p = &data[0];
	const uint8_t* pEnd = p + data.size();
	if (p[0] != 'M' || p[1] != 'S' || p[2] != 'H') {
	  return ImportMeshResult(ImportMeshResult::Result::invalidHeader);
	}
	p += 3;
	const int count = *p;
	p += 1;
	/*const uint32_t vboOffset = GetValue(p, 4);*/ p += 4;
	const uint32_t vboByteSize = GetValue(p, 4); p += 4;
	const uint32_t iboByteSize = GetValue(p, 4); p += 4;
	if (p >= pEnd) {
	  return ImportMeshResult(ImportMeshResult::Result::noData);
	}

	GLuint iboBaseOffset = iboEnd;
	ImportMeshResult  result(ImportMeshResult::Result::success);
	result.meshes.reserve(count);
	for (int i = 0; i < count; ++i) {
	  Mesh m;
	  const uint32_t nameLength = *p++;
	  m.id.assign(p, p + nameLength); p += nameLength;
	  const size_t materialCount = *p++;
	  p += (4 - (nameLength + 2) % 4) % 4;
	  m.materialList.resize(materialCount);
	  for (auto& e : m.materialList) {
		e.iboOffset = iboBaseOffset; p += 4;
		e.iboSize = GetValue(p, 2); p += 2;
		e.material.color.r = *p++;
		e.material.color.g = *p++;
		e.material.color.b = *p++;
		e.material.color.a = *p++;
		e.material.metallic.Set(static_cast<float>(*p++) / 255.0f);
		e.material.roughness.Set(static_cast<float>(*p++) / 255.0f);
		iboBaseOffset += e.iboSize * sizeof(GLushort);
	  }
	  result.meshes.push_back(m);
	  if (p >= pEnd) {
		return ImportMeshResult(ImportMeshResult::Result::invalidMeshInfo);
	  }
	}

	glBufferSubData(GL_ARRAY_BUFFER, vboEnd, vboByteSize, p);
	p += vboByteSize;
	if (p >= pEnd) {
	  return ImportMeshResult(ImportMeshResult::Result::invalidVBO);
	}

	std::vector<GLushort>  indices;
	indices.reserve(iboByteSize / sizeof(GLushort));
	const uint32_t offsetTmp = vboEnd / sizeof(Vertex);
	if (offsetTmp > 0xffff) {
	  return ImportMeshResult(ImportMeshResult::Result::indexOverflow);
	}
	const GLushort offset = static_cast<GLushort>(offsetTmp);
	for (uint32_t i = 0; i < iboByteSize; i += sizeof(GLushort)) {
	  indices.push_back(*reinterpret_cast<const GLushort*>(p) + offset);
	  p += sizeof(GLushort);
	  if (p >= pEnd) {
		return ImportMeshResult(ImportMeshResult::Result::invalidIBO);
	  }
	}
	glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, iboEnd, iboByteSize, &indices[0]);

	vboEnd += vboByteSize;
	iboEnd += iboByteSize;

	p += (4 - (reinterpret_cast<intptr_t>(p) % 4)) % 4;
	if (p >= pEnd) {
	  return result;
	}

	const uint32_t boneCount = GetValue(p, 2); p += 2;
	const uint32_t animationCount = GetValue(p, 2); p += 2;

	if (boneCount) {
	  JointList joints;
	  joints.resize(boneCount);
	  std::vector<std::vector<int>> parentIndexList;
	  parentIndexList.resize(boneCount);
	  for (uint32_t i = 0; i < boneCount; ++i) {
		if (p >= pEnd) {
		  return ImportMeshResult(ImportMeshResult::Result::invalidJointInfo);
		}
		Joint& e = joints[i];
		e.invBindPose.rot.x = GetFloat(p);
		e.invBindPose.rot.y = GetFloat(p);
		e.invBindPose.rot.z = GetFloat(p);
		e.invBindPose.rot.w = GetFloat(p);
		e.invBindPose.rot.Normalize();
		e.invBindPose.trans.x = GetFloat(p);
		e.invBindPose.trans.y = GetFloat(p);
		e.invBindPose.trans.z = GetFloat(p);
#if 0
		const Matrix4x3 m43 = ToMatrix(e.invBindPose.rot);
		Matrix4x4 m44;
		m44.SetVector(0, m43.GetVector(0));
		m44.SetVector(1, m43.GetVector(1));
		m44.SetVector(2, m43.GetVector(2));
		m44.SetVector(3, e.invBindPose.trans);
		m44.Inverse();
		Vector3F scale;
		m44.Decompose(&e.initialPose.rot, &scale, &e.initialPose.trans);
#else
		e.initialPose.rot = e.invBindPose.rot.Inverse();
		e.initialPose.trans = e.initialPose.rot.Apply(-e.invBindPose.trans);
#endif
		e.offChild = 0;
		e.offSibling = 0;
		const uint32_t parentIndex = GetValue(p, 4); p += 4;
		if (parentIndex != 0xffffffff) {
		  parentIndexList[parentIndex].push_back(i);
		}
	  }
	  for (uint32_t i = 0; i < boneCount; ++i) {
		const auto& e = parentIndexList[i];
		if (!e.empty()) {
		  int current = e[0];
		  joints[i].offChild = current - i;
		  Joint* pJoint = &joints[current];
		  for (auto itr = e.begin() + 1; itr != e.end(); ++itr) {
			const int sibling = *itr;
			pJoint->offSibling = sibling - current;
			pJoint = &joints[sibling];
			current = sibling;
		  }
		}
	  }
	  for (auto& e : result.meshes) {
		e.jointList = joints;
	  }
	}

	if (animationCount) {
	  LOGI("ImportMesh - Read animation:");
	  result.animations.reserve(animationCount);
	  for (uint32_t i = 0; i < animationCount; ++i) {
		Animation anm;
		const uint32_t nameLength = GetValue(p++, 1);
		char name[24];
		for (int i = 0; i < 24; ++i) {
		  name[i] = static_cast<char>(GetValue(p++, 1));
		}
		anm.id.assign(name, name + nameLength);
		anm.data.resize(boneCount);
		for (uint32_t bone = 0; bone < boneCount; ++bone) {
		  anm.data[bone].first = bone;
		}
		anm.loopFlag = static_cast<bool>(GetValue(p++, 1) != 0);
		const uint32_t keyframeCount = GetValue(p, 2); p += 2;
		anm.totalTime = GetFloat(p);
		LOGI("%s: %fsec", anm.id.c_str(), anm.totalTime);
		for (uint32_t keyframe = 0; keyframe < keyframeCount; ++keyframe) {
		  const float time = GetFloat(p);
#ifdef DEBUG_LOG_VERBOSE
		  LOGI("time=%f", time);
#endif // DEBUG_LOG_VERBOSE
		  for (uint32_t bone = 0; bone < boneCount; ++bone) {
			if (p >= pEnd) {
			  return ImportMeshResult(ImportMeshResult::Result::invalidAnimationInfo);
			}
			Animation::Element elem;
			elem.time = time;
			elem.pose.rot.x = GetFloat(p);
			elem.pose.rot.y = GetFloat(p);
			elem.pose.rot.z = GetFloat(p);
			elem.pose.rot.w = GetFloat(p);
			elem.pose.rot.Normalize();
			elem.pose.trans.x = GetFloat(p);
			elem.pose.trans.y = GetFloat(p);
			elem.pose.trans.z = GetFloat(p);
			anm.data[bone].second.push_back(elem);
#ifdef DEBUG_LOG_VERBOSE
			LOGI("%02d:(%+1.3f, %+1.3f, %+1.3f, %+1.3f) (%+1.3f, %+1.3f, %+1.3f)", bone, elem.pose.rot.w, elem.pose.rot.x, elem.pose.rot.y, elem.pose.rot.z, elem.pose.trans.x, elem.pose.trans.y, elem.pose.trans.z);
#endif // DEBUG_LOG_VERBOSE
		  }
		}
		result.animations.push_back(anm);
	  }
	}

	return result;
  }