gctGenerator/index.html

134 lines
5.8 KiB
HTML
Raw Normal View History

2017-09-28 22:21:01 +09:00
<!DOCTYPE HTML>
2017-09-28 01:14:25 +09:00
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
2017-09-28 01:19:07 +09:00
<link rel="stylesheet" href="style/style.css">
2017-09-28 22:21:01 +09:00
<title>SMS GCT Generator</title>
2017-09-28 01:14:25 +09:00
<script language="javascript">
2017-09-28 22:21:01 +09:00
function parseXML(name) {
2017-09-28 01:14:25 +09:00
var xml = new XMLHttpRequest();
var file = "codes/" + name + ".xml";
xml.onload = function() {
if (this.status == 200 && this.responseXML != null) {
var xmlData = xml.responseXML;
xmlData = (new DOMParser()).parseFromString(xml.responseText, "text/xml");
xmlData = xmlData.getElementsByTagName("code");
for (var i = 0; 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);
2017-09-28 22:21:01 +09:00
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)");
2017-09-28 01:14:25 +09:00
document.getElementById("checkList").appendChild(li);
}
2017-09-27 11:58:17 +09:00
}
2017-09-28 01:14:25 +09:00
};
xml.open("GET", file);
xml.send();
}
function downloadGCT(data, filename) {
var rawData = new Uint8Array(data.length / 2);
for (var x = 0; x < rawData.length; x++) {
rawData[x] = parseInt(data.substr(x * 2, 2), 16);
}
var file = new Blob([rawData], {
type: "application/octet-stream"
});
if (window.navigator.msSaveOrOpenBlob)
window.navigator.msSaveOrOpenBlob(file, filename);
else {
var a = document.createElement("a"),
url = window.URL.createObjectURL(file);
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
2017-09-27 11:58:17 +09:00
}
2017-09-28 01:14:25 +09:00
}
function generateGCT() {
2017-09-28 22:21:01 +09:00
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") {
data += codeList[i].getAttribute("data-codeSrc");
valueSelected = true;
}
}
2017-09-27 11:08:01 +09:00
2017-09-28 22:21:01 +09:00
if (valueSelected) {
//data = data.replace(/[\s\n\r\t]+/gm, "");
data += "FF00000000000000";
2017-09-27 11:08:01 +09:00
2017-09-28 22:21:01 +09:00
downloadGCT(data, document.getElementById("gameID").value + ".gct");
} else {
alert("No cheat(s) selected!");
2017-09-27 11:58:17 +09:00
}
2017-09-28 01:14:25 +09:00
}
function updateCodelist() {
2017-09-28 22:21:01 +09:00
document.getElementById("downloadButton").style.visibility = "visible";
2017-09-28 01:14:25 +09:00
document.getElementById("checkList").innerHTML = "";
var gameVersion = document.getElementById("gameID").value;
2017-09-28 22:21:01 +09:00
parseXML(gameVersion);
}
function updateDescription($this) {
document.getElementById("descriptionBox").style.visibility = "visible";
var description = "<p><h2>" + $this.getAttribute("data-codeName") + "</h2></p><p><i>Author: " + $this.getAttribute("data-codeAuthor") + "<br />Version: " + $this.getAttribute("data-codeVersion") + " (" + $this.getAttribute("data-codeDate") + ")</i></p>" + "<p>Description:<br />" + $this.getAttribute("data-codeDesc") + "</p>";
document.getElementById("descriptionBox").innerHTML = description;
}
function hideDescription() {
document.getElementById("descriptionBox").style.visibility = "hidden";
2017-09-28 01:14:25 +09:00
}
</script>
</head>
<body>
2017-09-28 22:21:01 +09:00
<div style="width: 100%; overflow: hidden;">
<h2>Mario Sunshine Cheatfile Generator</h2>
<div style="width: 510px; float: left;">
<select id="gameID" class="selectionHeader" onchange="updateCodelist()">
<option selected disabled hidden>Choose Version</option>
<option value="GMSE01">GMSE01 (NTSC-U)</option>
<option value="GMSJ01">GMSJ01 (NTSC-J 1.0)</option>
<option value="GMSP01">GMSP01 (PAL)</option>
</select>
<ul id="checkList" onmouseleave="hideDescription()">
</ul>
<button id="downloadButton" onclick="generateGCT()" style="visibility:hidden;">Download</button>
</div>
<div style="margin-left: 530px;">
<div id="descriptionBox" class="framed" style="visibility:hidden;">
</div>
</div>
</div>
2017-09-28 01:14:25 +09:00
</body>
<script language="javascript">
document.getElementById("checkList").addEventListener("click", function(ev) {
if (ev.target && ev.target.nodeName == "LI") {
ev.target.classList.toggle("checked");
}
});
</script>
2017-09-27 11:08:01 +09:00
2017-09-28 01:14:25 +09:00
</html>