Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually updating via json #453

Open
Koriebonx98 opened this issue Jan 26, 2024 · 2 comments
Open

Manually updating via json #453

Koriebonx98 opened this issue Jan 26, 2024 · 2 comments

Comments

@Koriebonx98
Copy link

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?

@Koriebonx98
Copy link
Author

~Xenia script General ~

Define the path to the exceptions file

$exceptionsFile = "{PlayniteDir}\Emulation\Emulators\Xenia\xenia canary\Achievements\exceptions.txt"

First, we need to read the exceptions from the file

$exceptions = @{}
Get-Content $exceptionsFile | ForEach-Object {
# Each line is in the format "{ImageNameNoExt} = GAMENAME"
$image_name, $game_name = $_ -split ' = '
if ($image_name -and $game_name) {
$exceptions[$image_name] = $game_name
}
}

Now, we can check if an image name is in the exceptions

Function Get-TitleName ($image_name_no_ext) {
if ($image_name_no_ext -and $exceptions.ContainsKey($image_name_no_ext)) {
# If it's in the exceptions, we use the corresponding game name
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 = "nnUnlocked`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

}

@Koriebonx98
Copy link
Author

~ 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 = "nnUnlocked`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

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant