TfToken usdWriteJob::writeVariants(const UsdPrim &usdRootPrim) { // Init parameters for filtering and setting the active variant std::string defaultModelingVariant; // Get the usdVariantRootPrimPath (optionally filter by renderLayer prefix) MayaPrimWriterPtr firstPrimWriterPtr = *mMayaPrimWriterList.begin(); std::string firstPrimWriterPathStr( firstPrimWriterPtr->getDagPath().fullPathName().asChar() ); std::replace( firstPrimWriterPathStr.begin(), firstPrimWriterPathStr.end(), '|', '/'); std::replace( firstPrimWriterPathStr.begin(), firstPrimWriterPathStr.end(), ':', '_'); // replace namespace ":" with "_" SdfPath usdVariantRootPrimPath(firstPrimWriterPathStr); usdVariantRootPrimPath = usdVariantRootPrimPath.GetPrefixes()[0]; // Create a new usdVariantRootPrim and reference the Base Model UsdRootPrim // This is done for reasons as described above under mArgs.usdModelRootOverridePath UsdPrim usdVariantRootPrim = mStage->DefinePrim(usdVariantRootPrimPath); TfToken defaultPrim = usdVariantRootPrim.GetName(); usdVariantRootPrim.GetReferences().AppendInternalReference(usdRootPrim.GetPath()); usdVariantRootPrim.SetActive(true); usdRootPrim.SetActive(false); // Loop over all the renderLayers for (unsigned int ir=0; ir < mRenderLayerObjs.length(); ++ir) { SdfPathTable<bool> tableOfActivePaths; MFnRenderLayer renderLayerFn( mRenderLayerObjs[ir] ); MString renderLayerName = renderLayerFn.name(); std::string variantName(renderLayerName.asChar()); // Determine default variant. Currently unsupported //MPlug renderLayerDisplayOrderPlug = renderLayerFn.findPlug("displayOrder", true); //int renderLayerDisplayOrder = renderLayerDisplayOrderPlug.asShort(); // The Maya default RenderLayer is also the default modeling variant if (mRenderLayerObjs[ir] == MFnRenderLayer::defaultRenderLayer()) { defaultModelingVariant=variantName; } // Make the renderlayer being looped the current one MGlobal::executeCommand(MString("editRenderLayerGlobals -currentRenderLayer ")+ renderLayerName, false, false); // == ModelingVariants == // Identify prims to activate // Put prims and parent prims in a SdfPathTable // Then use that membership to determine if a prim should be Active. // It has to be done this way since SetActive(false) disables access to all child prims. MObjectArray renderLayerMemberObjs; renderLayerFn.listMembers(renderLayerMemberObjs); std::vector< SdfPath > activePaths; for (unsigned int im=0; im < renderLayerMemberObjs.length(); ++im) { MFnDagNode dagFn(renderLayerMemberObjs[im]); MDagPath dagPath; dagFn.getPath(dagPath); dagPath.extendToShape(); SdfPath usdPrimPath; if (!TfMapLookup(mDagPathToUsdPathMap, dagPath, &usdPrimPath)) { continue; } usdPrimPath = usdPrimPath.ReplacePrefix(usdPrimPath.GetPrefixes()[0], usdVariantRootPrimPath); // Convert base to variant usdPrimPath tableOfActivePaths[usdPrimPath] = true; activePaths.push_back(usdPrimPath); //UsdPrim usdPrim = mStage->GetPrimAtPath(usdPrimPath); //usdPrim.SetActive(true); } if (!tableOfActivePaths.empty()) { { // == BEG: Scope for Variant EditContext // Create the variantSet and variant UsdVariantSet modelingVariantSet = usdVariantRootPrim.GetVariantSets().AppendVariantSet("modelingVariant"); modelingVariantSet.AppendVariant(variantName); modelingVariantSet.SetVariantSelection(variantName); // Set the Edit Context UsdEditTarget editTarget = modelingVariantSet.GetVariantEditTarget(); UsdEditContext editContext(mStage, editTarget); // == Activate/Deactivate UsdPrims UsdPrimRange it = UsdPrimRange::AllPrims(mStage->GetPseudoRoot()); std::vector<UsdPrim> primsToDeactivate; for ( ; it; ++it) { UsdPrim usdPrim = *it; // For all xformable usdPrims... if (usdPrim && usdPrim.IsA<UsdGeomXformable>()) { bool isActive=false; for (size_t j=0;j<activePaths.size();j++) { //primPathD.HasPrefix(primPathA); SdfPath activePath=activePaths[j]; if (usdPrim.GetPath().HasPrefix(activePath) || activePath.HasPrefix(usdPrim.GetPath())) { isActive=true; break; } } if (isActive==false) { primsToDeactivate.push_back(usdPrim); it.PruneChildren(); } } } // Now deactivate the prims (done outside of the UsdPrimRange // so not to modify the iterator while in the loop) for ( UsdPrim const& prim : primsToDeactivate ) { prim.SetActive(false); } } // == END: Scope for Variant EditContext } } // END: RenderLayer iterations // Set the default modeling variant UsdVariantSet modelingVariantSet = usdVariantRootPrim.GetVariantSet("modelingVariant"); if (modelingVariantSet.IsValid()) { modelingVariantSet.SetVariantSelection(defaultModelingVariant); } return defaultPrim; }
DWORD WINAPI CommandServerAnnounceStats_Thread(LPVOID lpParam) { auto* session = Blam::Network::GetActiveSession(); if (Blam::Network::GetLobbyType() != 2 || Blam::Network::GetNetworkMode() != 3) return false; std::vector<std::string> statsEndpoints; GetStatsEndpoints(statsEndpoints); if (statsEndpoints.size() == 0) { return false; } rapidjson::StringBuffer s; rapidjson::Writer<rapidjson::StringBuffer> writer(s); writer.StartObject(); writer.Key("gameVersion"); writer.String(Utils::Version::GetVersionString().c_str()); writer.Key("serverName"); writer.String(Modules::ModuleServer::Instance().VarServerName->ValueString.c_str()); writer.Key("serverPort"); writer.Int(Modules::ModuleServer::Instance().VarServerPort->ValueInt); writer.Key("port"); writer.Int(Pointer(0x1860454).Read<uint32_t>()); writer.Key("hostPlayer"); writer.String(Modules::ModulePlayer::Instance().VarPlayerName->ValueString.c_str()); writer.Key("game"); writer.StartObject(); writer.Key("sprintEnabled"); writer.Bool(Modules::ModuleServer::Instance().VarServerSprintEnabled->ValueInt != 0); writer.Key("sprintUnlimitedEnabled"); writer.Bool(Modules::ModuleServer::Instance().VarServerSprintUnlimited->ValueInt != 0); writer.Key("maxPlayers"); writer.Int(Modules::ModuleServer::Instance().VarServerMaxPlayers->ValueInt); std::string mapName((char*)Pointer(0x22AB018)(0x1A4)); std::wstring mapVariantName((wchar_t*)Pointer(0x1863ACA)); std::wstring variantName((wchar_t*)Pointer(0x23DAF4C)); Pointer &gameModePtr = ElDorito::GetMainTls(GameGlobals::GameInfo::TLSOffset)[0](GameGlobals::GameInfo::GameMode); uint32_t gameMode = gameModePtr.Read<uint32_t>(); int32_t variantType = Pointer(0x023DAF18).Read<int32_t>(); if (gameMode == 3) { if (mapName == "mainmenu") { mapName = std::string((char*)Pointer(0x19A5E49)); variantName = std::wstring((wchar_t*)Pointer(0x179254)); variantType = Pointer(0x179250).Read<uint32_t>(); } } writer.Key("mapName"); writer.String(Utils::String::ThinString(mapVariantName).c_str()); writer.Key("mapFile"); writer.String(mapName.c_str()); writer.Key("variant"); writer.String(Utils::String::ThinString(variantName).c_str()); if (variantType >= 0 && variantType < Blam::GameTypeCount) { writer.Key("variantType"); writer.String(Blam::GameTypeNames[variantType].c_str()); } uint32_t TeamMode = Pointer(0x019A6210).Read<uint32_t>(); writer.Key("teamGame"); writer.Bool(TeamMode != 0); if (TeamMode == 1){ writer.Key("teamScores"); writer.StartArray(); auto engineGlobalsPtr = ElDorito::GetMainTls(0x48); if (engineGlobalsPtr) { auto engineGobals = engineGlobalsPtr[0](0x101F4); for (int t = 0; t < 8; t++) { auto teamscore = engineGobals(t * 0x1A).Read<Blam::TEAM_SCORE>(); if (numberOfRounds > 1) writer.Int(teamscore.TotalScore); else writer.Int(teamscore.Score); } } writer.EndArray(); } writer.EndObject(); uint32_t playerInfoBase = 0x2162E08; Pointer p(0x023F1724); writer.Key("players"); writer.StartArray(); int peerIdx = session->MembershipInfo.FindFirstPeer(); while (peerIdx != -1) { int playerIdx = session->MembershipInfo.GetPeerPlayer(peerIdx); if (playerIdx != -1) { auto playerStats = Blam::Players::GetStats(playerIdx); writer.StartObject(); auto* player = &session->MembershipInfo.PlayerSessions[playerIdx]; std::string name = Utils::String::ThinString(player->Properties.DisplayName); struct in_addr inAddr; inAddr.S_un.S_addr = session->GetPeerAddress(peerIdx).ToInAddr(); char ipStr[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &inAddr, ipStr, sizeof(ipStr)); uint16_t team = Pointer(playerInfoBase + (5696 * playerIdx) + 32).Read<uint16_t>(); char uid[17]; Blam::Players::FormatUid(uid, player->Properties.Uid); Pointer pvpBase(0x23F5A98); writer.Key("name"); writer.String(name.c_str()); writer.Key("ip"); writer.String(ipStr); writer.Key("team"); writer.Int(team); writer.Key("playerIndex"); writer.Int(playerIdx); writer.Key("uid"); writer.String(uid); std::stringstream color; color << "#" << std::setw(6) << std::setfill('0') << std::hex << player->Properties.Customization.Colors[Blam::Players::ColorIndices::Primary]; writer.Key("primaryColor"); writer.String(color.str().c_str()); writer.Key("playerGameStats"); writer.StartObject(); writer.Key("score"); writer.Int(playerStats.Score); writer.Key("kills"); writer.Int(playerStats.Kills); writer.Key("assists"); writer.Int(playerStats.Assists); writer.Key("deaths"); writer.Int(playerStats.Deaths); writer.Key("betrayals"); writer.Int(playerStats.Betrayals); writer.Key("timeSpentAlive"); writer.Int(playerStats.TimeSpentAlive); writer.Key("suicides"); writer.Int(playerStats.Suicides); writer.Key("bestStreak"); writer.Int(playerStats.BestStreak); writer.EndObject(); //MEDALS writer.Key("playerMedals"); writer.StartArray(); for (int i = 0; i < Blam::Tags::Objects::MedalType::MedalCount; i++) { if (playerStats.Medals[i] > 0) { writer.StartObject(); writer.Key("medalName"); writer.String(Blam::Tags::Objects::MedalTypeNames[i].c_str()); writer.Key("count"); writer.Int(playerStats.Medals[i]); writer.EndObject(); } } //The sniper headshots medal is broken, so lets get it manually by grabbing the headshots from each sniper uint16_t SniperRifleHeadshots = p((playerIdx * 0x438) + 0x1F6).Read<uint16_t>(); uint16_t BeamRifleHeadshots = p((playerIdx * 0x438) + 0x202).Read<uint16_t>(); writer.StartObject(); writer.Key("medalName"); writer.String("SniperHeadshots"); writer.Key("count"); writer.Int(SniperRifleHeadshots + BeamRifleHeadshots); writer.EndObject(); writer.EndArray(); //WEAPONS writer.Key("playerWeapons"); writer.StartArray(); for (int i = 0; i < Blam::Tags::Objects::DamageReportingType::DamageCount; i++) { if (playerStats.WeaponStats[i].Initialized == 1) { writer.StartObject(); writer.Key("weaponName"); writer.String(Blam::Tags::Objects::DamageReportingTypeNames[i].c_str()); writer.Key("weaponIndex"); writer.Int(i + 1); writer.Key("kills"); writer.Int(playerStats.WeaponStats[i].Kills); writer.Key("killedBy"); writer.Int(playerStats.WeaponStats[i].KilledBy); writer.Key("betrayalsWith"); writer.Int(playerStats.WeaponStats[i].BetrayalsWith); writer.Key("suicidesWith"); writer.Int(playerStats.WeaponStats[i].SuicidesWith); writer.Key("headshotsWith"); writer.Int(playerStats.WeaponStats[i].HeadshotsWith); writer.EndObject(); } } writer.EndArray(); writer.Key("otherStats"); writer.StartObject(); int nemesisIdx = 0; uint16_t nemesisKills = 0; int currentLocation = 0x02; for (int loc = 0; loc < 16; loc++) { uint16_t currKills = pvpBase((playerIdx * 0x40) + currentLocation).Read<uint16_t>(); if (currKills > nemesisKills) { nemesisKills = currKills; nemesisIdx = loc; } currentLocation += 0x04; } writer.Key("nemesisIndex"); writer.Int(nemesisIdx); writer.Key("kingsKilled"); writer.Int(playerStats.KingsKilled); writer.Key("humansInfected"); writer.Int(playerStats.HumansInfected); writer.Key("zombiesKilled"); writer.Int(playerStats.ZombiesKilled); writer.Key("timeInHill"); writer.Int(playerStats.TimeInHill); writer.Key("timeControllingHill"); writer.Int(playerStats.TimeControllingHill); writer.EndObject(); writer.Key("playerVersusPlayerKills"); writer.StartArray(); int pvpIndex = 0x00; for (int loc = 0; loc < 16; loc++) { writer.Int(pvpBase((playerIdx * 0x40) + pvpIndex).Read<uint16_t>()); pvpIndex += 0x04; } writer.EndArray(); writer.EndObject(); } peerIdx = session->MembershipInfo.FindNextPeer(peerIdx); } writer.EndArray(); writer.EndObject(); for (auto server : statsEndpoints) { HttpRequest req(L"ElDewrito/" + Utils::String::WidenString(Utils::Version::GetVersionString()), L"", L""); try { std::string sendObject = s.GetString(); if (!req.SendRequest(Utils::String::WidenString(server), L"POST", L"", L"", L"Content-Type: application/json\r\n", (void*)sendObject.c_str(), sendObject.length())) { Utils::Logger::Instance().Log(Utils::LogTypes::Network, Utils::LogLevel::Info, "Unable to connect to stats server"); } } catch (...) { Utils::Logger::Instance().Log(Utils::LogTypes::Network, Utils::LogLevel::Info, "Exception while sending stats to server"); } } return true; }