Open Koriebonx98 opened 10 months ago
~Xenia script General ~
$exceptionsFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements\exceptions.txt"
$exceptions = @{} Get-Content $exceptionsFile | ForEach-Object {
$image_name, $game_name = $_ -split ' = '
if ($image_name -and $game_name) {
$exceptions[$image_name] = $game_name
}
}
Function Get-TitleName ($image_name_no_ext) { if ($image_name_no_ext -and $exceptions.ContainsKey($image_name_no_ext)) {
return $exceptions[$image_name_no_ext]
} else {
# If it's not in the exceptions, we use the image name itself
return $image_name_no_ext
}
}
$logFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\xenia.log" $textFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements{ImageNameNoExt}.txt" $jsonFile = "{PlayniteDir}\ExtensionsData\cebe6d32-8c46-4459-b993-5a5189d60788\SuccessStory{DatabaseId}.json" $newJsonFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements{DatabaseId}.json"
Copy-Item $jsonFile $newJsonFile
if (Test-Path $logFile) {
$logContent = Get-Content $logFile
$unlockedAchievements = $logContent | Select-String -Pattern "Achievement unlocked:" -AllMatches | Select-Object -ExpandProperty Line
$unlockedSection = "n
nUnlocked`n"
foreach ($achievement in $unlockedAchievements) {
$achievementName = $achievement -replace "Achievement unlocked:", "" -replace "`r", "" -replace "i> F8000034", ""
$achievementName = $achievementName.Trim()
$unlockedSection += "`n`"" + $achievementName + "`" - " + (Get-Date -Format "yyyy-MM-ddTHH:mm:ss")
}
$titleIndex = $logContent | Select-String -Pattern "Title name: $(Get-TitleName $ImageNameNoExt)" -List | Select-Object -ExpandProperty LineNumber
$endIndex = $logContent | Select-String -Pattern "----------------- END OF ACHIEVEMENTS ----------------" -List | Select-Object -ExpandProperty LineNumber
if ($titleIndex -and $endIndex) {
$allAchievements = $logContent[$titleIndex..($endIndex - 1)]
$lockedAchievementsSection = "`n`nLocked Achievements`n"
foreach ($achievement in $allAchievements) {
$achievementName = $achievement -replace "Achievement unlocked:", "" -replace "`r", "" -replace "i> F800000C", ""
$achievementName = $achievementName.Trim()
if ($achievementName -notin $unlockedAchievements) {
$achievementName = $achievementName -split "-" | Select-Object -Index 1
$lockedAchievementsSection += "`n`"" + $achievementName.Trim() + "`""
}
}
$output = $unlockedSection + $lockedAchievementsSection
$output | Out-File $textFile
}
$textContent = Get-Content $textFile -Raw
# Remove the prefix from each line in the text file
$textContent = $textContent -replace "`"i> F8000058 ", "`""
# Write the modified content back to the text file
$textContent | Out-File $textFile
if (Test-Path $newJsonFile) {
$jsonContent = Get-Content $newJsonFile | ConvertFrom-Json
# Update the 'DateLastRefresh' field with the current date and time
$jsonContent.DateLastRefresh = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
$achievementNames = $textContent -split "`n" | Where-Object { $_ -like "`"*`"" } | ForEach-Object { $_ -replace "`"", "" }
foreach ($achievementName in $achievementNames) {
$index = $jsonContent.Items | Where-Object { $_.Name -eq $achievementName.Trim() }
if ($index) {
$index.DateUnlocked = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
}
}
$jsonContent | ConvertTo-Json -Compress | ForEach-Object { [System.Text.RegularExpressions.Regex]::Unescape($_) } | Set-Content $newJsonFile
}
# Replace the original JSON file with the updated one
Copy-Item -Path $newJsonFile -Destination $jsonFile -Force
}
~ Skate 1 - Xenia Script ~
$logFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\xenia.log" $textFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements{ImageNameNoExt}.txt" $jsonFile = "{PlayniteDir}\ExtensionsData\cebe6d32-8c46-4459-b993-5a5189d60788\SuccessStory{DatabaseId}.json" $newJsonFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements{DatabaseId}.json"
Copy-Item $jsonFile $newJsonFile
if (Test-Path $logFile) {
$logContent = Get-Content $logFile
$unlockedAchievements = $logContent | Select-String -Pattern "Achievement unlocked:" -AllMatches | Select-Object -ExpandProperty Line
$unlockedSection = "n
nUnlocked`n"
foreach ($achievement in $unlockedAchievements) {
$achievementName = $achievement -replace "Achievement unlocked:", "" -replace "`r", "" -replace "i> F8000034", ""
$achievementName = $achievementName.Trim()
$unlockedSection += "`n`"" + $achievementName + "`" - " + (Get-Date -Format "yyyy-MM-ddTHH:mm:ss")
}
$titleIndex = $logContent | Select-String -Pattern "skate." -List | Select-Object -ExpandProperty LineNumber
$endIndex = $logContent | Select-String -Pattern "----------------- END OF ACHIEVEMENTS ----------------" -List | Select-Object -ExpandProperty LineNumber
if ($titleIndex -and $endIndex) {
$allAchievements = $logContent[$titleIndex..($endIndex - 1)]
$lockedAchievementsSection = "`n`nLocked Achievements`n"
foreach ($achievement in $allAchievements) {
$achievementName = $achievement -replace "Achievement unlocked:", "" -replace "`r", "" -replace "i> F800000C", ""
$achievementName = $achievementName.Trim()
if ($achievementName -notin $unlockedAchievements) {
$achievementName = $achievementName -split "-" | Select-Object -Index 1
$lockedAchievementsSection += "`n`"" + $achievementName + "`""
}
}
$output = $unlockedSection + $lockedAchievementsSection
$output | Out-File $textFile
}
$textContent = Get-Content $textFile -Raw
if (Test-Path $newJsonFile) {
$jsonContent = Get-Content $newJsonFile | ConvertFrom-Json
# Update the 'DateLastRefresh' field with the current date and time
$jsonContent.DateLastRefresh = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
$achievementNames = $textContent -split "`n" | Where-Object { $_ -like "`"*`"" } | ForEach-Object { $_ -replace "`"", "" }
foreach ($achievementName in $achievementNames) {
$index = $jsonContent.Items | Where-Object { $_.Name -eq $achievementName.Trim() }
if ($index) {
$index.DateUnlocked = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
}
}
$jsonContent | ConvertTo-Json -Compress | ForEach-Object { [System.Text.RegularExpressions.Regex]::Unescape($_) } | Set-Content $newJsonFile
}
# Replace the original JSON file with the updated one
Copy-Item -Path $newJsonFile -Destination $jsonFile -Force
}
ill update this with a link and info on how to set up,, if you wish to add this to success sttory addon feel free
Ive made custom script that looks in xenia log for all achievements. extracts in txt in sections of "Locked" and "Unlocked"
e.g Unlocked: "Looking Good" - 2024-01-01-03
Locked: "Horder" - Own 5 cars
it also uses {DatabseId}.json copies, edits the copy with info from txt such as what's unlocked and the date and time in the same format as original json, it then replaces orginal.json file keeping same structure and compression
result = it updates json with correct data but doesn't update in playnite unless using playnite gui and manually updating Game data that way.
Script is still early stages and some games Dont work unless static string e.g would need replace {ImageNameNoExt} in script with static string fort some games such as "skate." even if iso or game name is same it don't work unless static string is used
other games work if in "exception.txt" as format followed
"Forza Horizon 2 Presents Fast & Furious" = "FH2: Fast & Furious"
if can update achievement data this way then we can add support for xbox 360 Games via "Xenia"
if also works with xenia can we do it for any emu or game, as long as it points to {DatabaseId}.json?
e,g games that use SSE or Goldberg generate data to json file or txt file with stats ect. cant we uses this?