Skip to content

Instantly share code, notes, and snippets.

@cborac
Created October 10, 2024 22:04
Show Gist options
  • Save cborac/5eb3a534434425333c9a85c7f3c6e8b5 to your computer and use it in GitHub Desktop.
Save cborac/5eb3a534434425333c9a85c7f3c6e8b5 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Wii Shop Channel Polyfill
// @version 2024-02-03
// @description Mocks WSC APIs normally provided by the channel itself
// @author Sards
// @match https://oss-auth.shop.wii.com/*
// @match *
// @icon https://www.google.com/s2/favicons?sz=64&domain=wii.com
// @run-at document-start
// @grant none
// ==/UserScript==
window.trace = console.trace
class wiiShop {
constructor() {
this.title = "Wii Shop Channel"
this.menuBtn = "Wii Menu"
this.retryBtn = "Try Again"
this.getLogUrl = "http://oss.shop.wii.com/oss/getLog"
this.connecting = "Connecting..."
}
enableHRP() { }
disableHRP() { }
returnToUpdate() { }
setWallpaper() { }
enableHRP() { }
disableHRP() { }
error(errcode, errortype) {
console.error(`${errcode} ${errortype}`)
}
returnToMenu() { }
beginWaiting() { }
endWaiting() { }
}
window.wiiShop = wiiShop
class wiiSound {
playSE(sound) {
console.log(`Playing ${sound}`)
}
}
window.wiiSound = wiiSound
class ECommerceInterface {
constructor() {}
set progress(value) {
localStorage.setItem("__deviceProgress", JSON.stringify(value))
}
get progress() {
return JSON.parse(localStorage.getItem("__deviceProgress", "{ status: 0 }")) || { status: 0 }
}
set tmds(value) {
localStorage.setItem("__installedTMDs", JSON.stringify(value))
}
get tmds() {
return JSON.parse(localStorage.getItem("__installedTMDs", "[]")) || []
}
getSessionValue(key) {
return localStorage.getItem(key)
}
setSessionValue(key, value) {
return localStorage.setItem(key, value)
}
getTitleInfos() {
return []
}
reportCSS(callerType, helperId, helperIdKind, helpeeId, helpeeIdKind, survey, postalCode) {
return ""
}
confirmCSS(callerType,
helperId, helperIdKind,
helpeeId, helpeeIdKind,
confirmation, notes) {
return ""
}
getDeviceInfo() {
return {
totalBlocks: 500000000,
usedBlocks: 0,
totalSysBlocks: 4000000,
usedSysBlocks: 0,
blockSize: 1,
titleId: "0001000248414241",
freeChannelAppCount: 500,
maxUserInodes: 500,
usedUserInodes: 4
}
}
downloadTitle(titleId) {
this.progress = {
status: -4009,
operation: "Downloading",
phase: EC_PHASE_DownloadingContent
}
setTimeout(() => {
this.tmds = [...this.tmds, titleId]
this.progress = {
status: 0,
operation: "Downloading",
phase: EC_ERROR_OK
}
}, 1000)
return this.progress
}
getWeakToken() {
return "AAA"
}
getTitleInfo(id) {
return {
isTmdPresent: this.tmds.includes(id),
version: 1,
isOnDevice: false,
occupiedUserBlocks: 0
}
}
setWebSvcUrls() {}
setContentUrls() {}
getProgress() {
return this.progress
}
cancelOperation() {
return
}
checkDeviceStatus() {
return this.getProgress()
}
refreshCachedBalance() {
return this.getProgress()
}
getCachedBalance() {
return 10000
}
getTicketInfos(id) {
return {
deviceId: 2,
licenseType: ES_LICENSE_MASK
}
}
purchaseTitle(titleId, itemId, price, payment, limits, downloadContent, _, purchaseInfo, discount) {
console.log(titleId, itemId, price, payment, limits, downloadContent, _, purchaseInfo, discount)
return {
status: EC_ERROR_OK
}
}
}
window.ECommerceInterface = ECommerceInterface
class ECTitleLimits {
}
window.ECTitleLimits = ECTitleLimits
class ECAccountPayment {
}
window.ECAccountPayment = ECAccountPayment
class ECPrice {
constructor(value, type) {
this.value = value
this.type = type
}
}
window.ECPrice = ECPrice
class wiiSDCard {
// objSD.checkValidSD(titleId, titleSizeKB) : Check SD status (Error check)
// objSD.isInserted() : Check if SD card is inserted in device
// objSD.getFreeKBytes() : Get free SD area size (KBytes)
// objSD.setJournalFlag(titleId) : Set SD mode flag into NAND used during DL
// objSD.backupToSDCard(titleId) : Backup title data to SD
// objSD.hasProgressFinished() : Check the progress and status of SHOPSDLib processing
// objSD.isJournalValue() : Return value of SHOPSDIsJournaling()
// objSD.stopBackupToSDCard() : Stop backupToSDCard
// objSD.setCancelJournal() : Remove SD mode flag from NAND used during DL
// objSD.getSDBackupSize() : Get necessary SD Backup Size
checkValidSD() { return 0 }
isInserted() { return true }
getFreeKBytes() { return 50000 }
getSDBackupSize() { return 0 }
}
window.wiiSDCard = wiiSDCard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment