Skip to content

Commit

Permalink
Added function to notify when games are played. Fixed an issue where …
Browse files Browse the repository at this point in the history
…the steam apps folder was being ignored.
  • Loading branch information
oxters168 committed Dec 18, 2024
1 parent 2a54871 commit 3ddeb77
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ cellid.txt
loginkey.txt
sentry.bin
server_list.bin
steamapps/
userfiles/
/steamapps/
/userfiles/

# Kotlin 2.0
/.kotlin/sessions/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package `in`.dragonbra.javasteam.steam.handlers.steamapps

data class AppProcessInfo(
val processId: Int,
val processIdParent: Int,
val parentIsSteam: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package `in`.dragonbra.javasteam.steam.handlers.steamapps

@Suppress("ArrayInDataClass")
data class GamePlayedInfo(
val steamIdGs: Long = 0,
val gameId: Long,
val deprecatedGameIpAddress: Int = 0,
val gamePort: Int = 0,
val isSecure: Boolean = false,
val token: ByteArray = byteArrayOf(),
val gameExtraInfo: String = "",
val gameDataBlob: ByteArray? = null,
val processId: Int,
val streamingProviderId: Int = 0,
val gameFlags: Int = 0,
val ownerId: Int,
val vrHmdVendor: String = "",
val vrHmdModel: String = "",
val launchOptionType: Int = 0,
val primaryControllerType: Int = -1,
val primarySteamControllerSerial: String = "",
val totalSteamControllerCount: Int = 0,
val totalNonSteamControllerCount: Int = 0,
val controllerWorkshopFileId: Long = 0,
val launchSource: Int = 0,
val vrHmdRuntime: Int = 0,
val gameIpAddress: ProtoIPAddress<*>? = null,
val controllerConnectionType: Int = 0,
val gameOsPlatform: Int = -1,
val gameBuildId: Int,
val compatToolId: Int = 0,
val compatToolCmd: String = "",
val compatToolBuildId: Int = 0,
val betaName: String = "",
val dlcContext: Int = 0,
val processIdList: List<AppProcessInfo> = emptyList(),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package `in`.dragonbra.javasteam.steam.handlers.steamapps

abstract class ProtoIPAddress<T> {
abstract fun getValue(): T
}
data class ProtoIPv4(
private val ip: Int
) : ProtoIPAddress<Int>() {
override fun getValue(): Int {
return ip
}
}
@Suppress("ArrayInDataClass")
data class ProtoIPv6(
private val ip: ByteArray
) : ProtoIPAddress<ByteArray>() {
override fun getValue(): ByteArray {
return ip
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package `in`.dragonbra.javasteam.steam.handlers.steamapps

import com.google.protobuf.ByteString
import `in`.dragonbra.javasteam.base.ClientMsg
import `in`.dragonbra.javasteam.base.ClientMsgProtobuf
import `in`.dragonbra.javasteam.base.IPacketMsg
import `in`.dragonbra.javasteam.enums.EMsg
import `in`.dragonbra.javasteam.enums.EOSType
import `in`.dragonbra.javasteam.generated.MsgClientGetLegacyGameKey
import `in`.dragonbra.javasteam.protobufs.steamclient.*
import `in`.dragonbra.javasteam.protobufs.steamclient.SteammessagesClientserver.CMsgClientGamesPlayed
import `in`.dragonbra.javasteam.protobufs.steamclient.SteammessagesClientserver.CMsgClientGetAppOwnershipTicket
import `in`.dragonbra.javasteam.protobufs.steamclient.SteammessagesClientserver2.CMsgClientCheckAppBetaPassword
import `in`.dragonbra.javasteam.protobufs.steamclient.SteammessagesClientserver2.CMsgClientGetDepotDecryptionKey
Expand Down Expand Up @@ -295,6 +299,87 @@ class SteamApps : ClientMsgHandler() {
return AsyncJobSingle(client, request.sourceJobID)
}

/**
* Notify Steam of games being played
* TODO: Support appid/non-steam game, [relevant discord msg](https://discord.com/channels/420907597906968586/420907598527594497/464573011274629151)
*
* @param gamesPlayed The list of the different game processes
* @param clientOsType The OS type of the client launching the games
*/
@Suppress("DuplicatedCode", "unused")
@JvmOverloads
// JavaSteam Addition
fun notifyGamesPlayed(
gamesPlayed: List<GamePlayedInfo> = emptyList(),
clientOsType: EOSType,
cloudGamingPlatform: Int = 0,
recentReAuthentication: Boolean = false,
) {
val request = ClientMsgProtobuf<CMsgClientGamesPlayed.Builder>(
CMsgClientGamesPlayed::class.java,
EMsg.ClientGamesPlayedWithDataBlob
).apply {
sourceJobID = client.getNextJobID()

body.addAllGamesPlayed(gamesPlayed.map { gamePlayed ->
CMsgClientGamesPlayed.GamePlayed.newBuilder().apply {
this.steamIdGs = gamePlayed.steamIdGs
this.gameId = gamePlayed.gameId
this.deprecatedGameIpAddress = gamePlayed.deprecatedGameIpAddress
this.gamePort = gamePlayed.gamePort
this.isSecure = gamePlayed.isSecure
this.token = ByteString.copyFrom(gamePlayed.token)
this.gameExtraInfo = gamePlayed.gameExtraInfo
gamePlayed.gameDataBlob?.let { gameDataBlob ->
this.gameDataBlob = ByteString.copyFrom(gameDataBlob)
}
this.processId = gamePlayed.processId
this.streamingProviderId = gamePlayed.streamingProviderId
this.gameFlags = gamePlayed.gameFlags
this.ownerId = gamePlayed.ownerId
this.vrHmdVendor = gamePlayed.vrHmdVendor
this.vrHmdModel = gamePlayed.vrHmdModel
this.launchOptionType = gamePlayed.launchOptionType
this.primaryControllerType = gamePlayed.primaryControllerType
this.primarySteamControllerSerial = gamePlayed.primarySteamControllerSerial
this.totalSteamControllerCount = gamePlayed.totalSteamControllerCount
this.totalNonSteamControllerCount = gamePlayed.totalNonSteamControllerCount
this.controllerWorkshopFileId = gamePlayed.controllerWorkshopFileId
this.launchSource = gamePlayed.launchSource
this.vrHmdRuntime = gamePlayed.vrHmdRuntime
gamePlayed.gameIpAddress?.let { ipAddress ->
this.gameIpAddress = SteammessagesBase.CMsgIPAddress.newBuilder().apply {
when (ipAddress) {
is ProtoIPv4 -> this.v4 = ipAddress.getValue()
is ProtoIPv6 -> this.v6 = ByteString.copyFrom(ipAddress.getValue())
}
}.build()
}
this.controllerConnectionType = gamePlayed.controllerConnectionType
this.gameOsPlatform = gamePlayed.gameOsPlatform
this.gameBuildId = gamePlayed.gameBuildId
this.compatToolId = gamePlayed.compatToolId
this.compatToolCmd = gamePlayed.compatToolCmd
this.compatToolBuildId = gamePlayed.compatToolBuildId
this.betaName = gamePlayed.betaName
this.dlcContext = gamePlayed.dlcContext
this.addAllProcessIdList(gamePlayed.processIdList.map { processInfo ->
CMsgClientGamesPlayed.ProcessInfo.newBuilder().apply {
this.processId = processInfo.processId
this.processIdParent = processInfo.processIdParent
this.parentIsSteam = processInfo.parentIsSteam
}.build()
})
}.build()
})
body.clientOsType = clientOsType.code()
body.cloudGamingPlatform = cloudGamingPlatform
body.recentReauthentication = recentReAuthentication
}

client.send(request)
}

/**
* Handles a client message. This should not be called directly.
*
Expand Down

0 comments on commit 3ddeb77

Please sign in to comment.