Last active
September 27, 2015 14:52
-
-
Save MikuAuahDark/bef60ab0e5d923f61601 to your computer and use it in GitHub Desktop.
SaveCard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CardInstall.ps1 | |
<# | |
Script to add all cards to database as .card files. | |
The specification of the .card file can be found here: | |
(some_link) | |
#> | |
# Enumeration definition | |
$rarityEnum=@{N=0;R=1;SR=2;UR=3} | |
$attributeEnum=@{Smile=0;Pure=1;Cool=2;All=3} | |
$attrEnumStr=@("smile";"pure";"cool";"all") | |
$statisticsEnumStr=@("minimum";"non_idolized_maximum";"idolized_maximum") | |
$skillEnum=@{None=0;"Score Up"=1;"Rhythmical Charm"=1;"Perfect Charm"=1;"Timer Charm"=1;Healer=2;"Timer Yell"=2;"Perfect Yell"=2;"Musical Yell"=2;"Perfect Lock"=3} | |
$typeAttrEnum=@{Princess=0;Angel=1;Empress=2;Heart=3;Power=4} | |
$utf8Encoder=[System.Text.Encoding]::UTF8 | |
$epoch1970=new-object System.DateTime -ArgumentList 1970,1,1,0,0,0,([System.DateTimeKind]::Utc) | |
# Successful fetched cards | |
$CardChecklist=@{} | |
function WriteVariableValue([System.IO.BinaryWriter]$w,[byte[]]$i) { | |
$w.Write($i.Count) | |
$w.Write($i) | |
} | |
function SaveCard([int]$card_id) { | |
$card_data=$null | |
while($card_data -eq $null) { | |
try { | |
$card_data=wget ("schoolido.lu/api/cards/{0}/" -f $card_id) -timeoutsec 15 | |
} catch { | |
Write-Host("{0}... Retrying..." -f $error[0].ToString()) | |
} | |
} | |
$card_file=new-object System.IO.FileStream -ArgumentList ("{0}\card\{1}.card" -f ($pwd -as [string]),$card_id),([System.IO.FileMode]::Create) | |
$card_json=ConvertFrom-Json $card_data.Content | |
$bin_write=new-object System.IO.BinaryWriter -ArgumentList $card_file | |
$bin_write.Write(1146241347) # CARD FourCC | |
$bin_write.Write($card_id) | |
$bin_write.Write((($rarityEnum[$card_json.rarity] -shl 5) -bor ($attributeEnum[$card_json.attribute] -shl 3) -bor (0,4)[$card_json.is_promo] -bor (0,2)[$card_json.japan_only] -bor (0,1)[$card_json.is_special]) -as [byte]) | |
$bin_write.Write((($card_json.hp -shl 2) -bor $skillEnum[($card_json.skill,"None" -ne $null)[0]]) -as [byte]) | |
WriteVariableValue $bin_write $utf8Encoder.GetBytes($card_json.name) | |
if($card_json.is_promo -eq $true) { | |
WriteVariableValue $bin_write $utf8Encoder.GetBytes($card_json.promo_item) | |
} | |
if($card_json.release_date -ne $null) { | |
$bin_write.Write(([System.DateTime]::Parse($card_json.release_date)-$epoch1970).TotalSeconds -as [int]) | |
} else { | |
$bin_write.Write((-1) -as [int]) | |
} | |
foreach($x in @("smile","pure","cool")) { | |
foreach($y in @("minimum","non_idolized_maximum","idolized_maximum")) { | |
$bin_write.Write(($card_json.("{0}_statistics_{1}" -f $y,$x)) -as [int16]) | |
} | |
} | |
if($card_json.center_skill -ne $null) { | |
$card_json.center_skill | where {$_ -match "(\w+) (\w+)"} | foreach { | |
$bin_write.Write((($attributeEnum[$matches[1]] -shl 3) -bor $typeAttrEnum[$matches[2]]) -as [byte]) | |
} | |
} else { | |
$bin_write.Write(255 -as [byte]) | |
} | |
if($card_json.skill_details -ne $null) { | |
WriteVariableValue $bin_write $utf8Encoder.GetBytes($card_json.skill_details) | |
} else { | |
$bin_write.Write(0 -as [int]) | |
} | |
$bin_write.Write($card_json.non_idolized_max_level -as [byte]) | |
$bin_Write.Write($card_json.idolized_max_level -as [byte]) | |
$card_file.Close() | |
} | |
function SaveCurrentChecklist() { | |
$file_handle=new-object System.IO.FileStream -ArgumentList ("{0}\SuccessfulFetchedCard.txt" -f ($pwd -as [string])),([System.IO.FileMode]::Create) | |
$arr=@() | |
foreach($x in $CardChecklist) { | |
if($x.Values -eq $true) { | |
$arr+=$x.Keys | |
} | |
} | |
$file_handle.Write($x -join ",") | |
$file_handle.Close() | |
} | |
function FetchCards() { | |
$cardlist=$null | |
Write-Host "Get total cards..." | |
while($cardlist -eq $null) | |
try { | |
$cardlist=wget schoolido.lu/api/cards?page_size=2 -timeoutsec 15 | |
} catch { } | |
} | |
$cardlist=ConvertFrom-Json $cardlist.Content | |
Write-Host ("{0} cards ready" -f $cardlist.count) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment