gctGenerator/gctGenerator.js

193 lines
7.9 KiB
JavaScript
Raw Normal View History

2017-10-19 04:19:45 +09:00
if (navigator.userAgent.toLowerCase().indexOf("firefox") > -1) {
HTMLElement.prototype.click = function() {
var evt = this.ownerDocument.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}
2017-10-19 04:19:45 +09:00
}
2017-11-06 22:22:58 +09:00
document.getElementById("checkList").addEventListener("click", function(ev) {
if (ev.target && ev.target.nodeName == "LI") {
ev.target.classList.toggle("checked");
}
2017-11-06 22:22:58 +09:00
});
2017-10-19 04:19:45 +09:00
function parseXML(name) {
var xml = new XMLHttpRequest();
var file = "codes/" + name + ".xml";
xml.onreadystatechange = function() {
if (this.status == 200 && this.readyState == 4) {
var xmlData = xml.responseXML;
xmlData = (new DOMParser()).parseFromString(xml.responseText, "text/xml");
xmlData = xmlData.getElementsByTagName("code");
var i = 0;
for (; i < xmlData.length; i++) {
var li = document.createElement("li");
var desc = xmlData[i].getElementsByTagName("title")[0].textContent;
var t = document.createTextNode(desc);
li.appendChild(t);
li.setAttribute("data-codename", xmlData[i].getElementsByTagName("title")[0].textContent);
li.setAttribute("data-codeauthor", xmlData[i].getElementsByTagName("author")[0].textContent);
li.setAttribute("data-codedesc", xmlData[i].getElementsByTagName("description")[0].textContent);
li.setAttribute("data-codeversion", xmlData[i].getElementsByTagName("version")[0].textContent);
li.setAttribute("data-codedate", xmlData[i].getElementsByTagName("date")[0].textContent);
li.setAttribute("data-codesrc", xmlData[i].getElementsByTagName("source")[0].textContent.replace(/[\s\n\r\t]+/gm, ""));
li.setAttribute("onmouseover", "updateDescription(this)");
document.getElementById("checkList").appendChild(li);
}
button = document.getElementById("downloadButton");
button.style.visibility = "visible";
button.disabled = false;
button = document.getElementById("dolphinDownloadButton");
button.style.visibility = "visible";
button.disabled = false;
button = document.getElementById("gcmDownloadButton");
button.style.visibility = "visible";
button.disabled = false;
document.getElementById("gameID").disabled = false;
}
};
2017-11-06 22:22:58 +09:00
xml.open("GET", file);
xml.send();
2017-10-19 04:19:45 +09:00
}
function downloadFile(data, filename) {
2018-01-17 06:42:49 +09:00
var fname = filename.replace("GMSJ0A","GMSJ01");
var file = new Blob([data], {
type: "application/octet-stream"
});
if (window.navigator.msSaveOrOpenBlob)
2018-01-17 06:42:49 +09:00
window.navigator.msSaveOrOpenBlob(file, fname);
else {
var a = document.createElement("a"),
url = window.URL.createObjectURL(file);
a.href = url;
2018-01-17 06:42:49 +09:00
a.download = fname;
a.click();
setTimeout(function() {
window.URL.revokeObjectURL(url);
}, 500);
}
2017-10-19 04:19:45 +09:00
}
function generateGCT() {
if (document.getElementById("gameID").value === "Choose Version") {
alert("Select the game version!");
return;
}
var data = "00D0C0DE00D0C0DE";
var codeList = document.getElementById("checkList").getElementsByTagName("li");
var valueSelected = false;
for (var i = 0; i < codeList.length; i++) {
if (codeList[i].className === "checked") {
2018-01-09 07:46:18 +09:00
data += codeList[i].getAttribute("data-codesrc");
valueSelected = true;
2017-10-19 04:19:45 +09:00
}
}
2017-10-19 04:19:45 +09:00
if (valueSelected) {
data += "FF00000000000000";
var rawData = new Uint8Array(data.length / 2);
2017-10-19 04:19:45 +09:00
for (var x = 0; x < rawData.length; x++) {
rawData[x] = parseInt(data.substr(x * 2, 2), 16);
2017-10-19 04:19:45 +09:00
}
downloadFile(rawData, document.getElementById("gameID").value + ".gct");
} else {
alert("No cheat(s) selected!");
}
}
2017-12-05 14:58:00 +09:00
function generateTXT(s) {
if (document.getElementById("gameID").value === "Choose Version") {
alert("Select the game version!");
return;
}
if (s.id === "dolphinDownloadButton") var data = "Paste the following on top of your games .ini file:\r\n[Gecko]";
2018-01-17 06:42:49 +09:00
else var data = document.getElementById("gameID").value.replace("GMSJ0A","GMSJ01") + "\r\nSuper Mario Sunshine";
var codeList = document.getElementById("checkList").getElementsByTagName("li");
var valueSelected = false;
for (var i = 0; i < codeList.length; i++) {
if (codeList[i].className === "checked") {
data += "\r\n";
if (s.id === "gcmDownloadButton") data += "\r\n";
else data += "$";
2018-01-17 06:42:49 +09:00
data += codeList[i].getAttribute("data-codename") + " (" + codeList[i].getAttribute("data-codedate") + ") [" + codeList[i].getAttribute("data-codeauthor") + "]\r\n";
2018-01-09 07:46:18 +09:00
data += (codeList[i].getAttribute("data-codesrc").match(/.{8}/g).join(" ")).replace(/(.{17})./g, "$1\r\n");
valueSelected = true;
}
}
if (valueSelected) {
downloadFile(data, document.getElementById("gameID").value + ".txt");
} else {
alert("No cheat(s) selected!");
}
}
2017-10-19 04:19:45 +09:00
function updateCodelist() {
resetDescription();
document.getElementById("gameID").disabled = true;
button = document.getElementById("downloadButton");
button.style.visibility = "hidden";
button.disabled = true;
button = document.getElementById("dolphinDownloadButton");
button.style.visibility = "hidden";
button.disabled = true;
button = document.getElementById("gcmDownloadButton");
button.style.visibility = "hidden";
button.disabled = true;
document.getElementById("checkList").innerHTML = "";
var gameVersion = document.getElementById("gameID").value;
parseXML(gameVersion);
2017-10-19 04:19:45 +09:00
}
2017-12-05 14:58:00 +09:00
function updateDescription(s) {
document.getElementById("descriptionBox").innerHTML = "<h2>" +
2018-01-09 07:46:18 +09:00
s.getAttribute("data-codename") + "</h2><p style=\"margin:0\"><i>Author(s): " +
s.getAttribute("data-codeauthor") + "</i></p><p style=\"margin:0\"><i>Version: " +
s.getAttribute("data-codeversion") + " (" +
s.getAttribute("data-codedate") + ")</i></p>" + "<h4>Description:</h4><p>" +
s.getAttribute("data-codedesc") + "</p>";
2017-12-05 14:58:00 +09:00
}
function setButtonDescription(s) {
if (s.id === "downloadButton")
document.getElementById("descriptionBox").innerHTML = "<h2>Download GCT</h2><p>Download the cheats in the GCT format for use with Nintendont.</p>";
else if (s.id === "dolphinDownloadButton")
2018-01-09 07:46:18 +09:00
document.getElementById("descriptionBox").innerHTML = "<h2>Download for Dolphin</h2><p>Download a textfile containing the formatted codes for use with Dolphin. Copy the contents of the file on top of your games .ini file.</p><p>You can open the .ini file by right clicking the game in Dolphin. In the context menu select \"<i>Properties</i>\" and then \"<i>Edit configuration</i>\".</p>";
else
document.getElementById("descriptionBox").innerHTML = "<h2>Download for Gecko Cheat Manager</h2><p>Download the cheats in a textfile formatted for use with the <a href=\"http://wiibrew.org/wiki/CheatManager\">Gecko Cheat Manager</a>. Place the txt file in SD:/txtcodes/.</p><p>A zip archive containing pregenerated txt files with all available codes on this site can be downloaded <a href=\"files/GCMCodes.zip\">here</a>.";
2017-10-19 04:19:45 +09:00
}
function resetDescription() {
document.getElementById("descriptionBox").innerHTML = "<p><h3>Select your codes from the list...</h3></p>";
2017-10-19 04:19:45 +09:00
}
function updateChangelog() {
var xml = new XMLHttpRequest();
var file = "changelog.xml";
xml.onload = function() {
if (this.status == 200 && this.responseXML != null) {
var changelogData = xml.responseXML;
changelogData = (new DOMParser()).parseFromString(xml.responseText, "text/xml");
changelogData = changelogData.getElementsByTagName("update");
for (var i = 0; i < changelogData.length && i < 5; i++) {
document.getElementById("changelog").innerHTML += "<p style=\"margin:0\"><i>" + changelogData[i].getElementsByTagName("date")[0].textContent + ":</i> " + changelogData[i].getElementsByTagName("change")[0].textContent + "</p>";
}
document.getElementById("changelog").innerHTML += "<a target=\"_blank\" href=\"changelog.html\"><i>more ...</i></a>";
};
}
xml.open("GET", file);
xml.send();
2017-12-05 14:58:00 +09:00
}