Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
SandeMC committed Jun 16, 2024
1 parent 947c7a6 commit 8b96864
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ <h2>Usage Instructions</h2>
<li>If some error appears, make sure to read the error properly. Also make sure your file is not renamed in any way and shows up as the game creates them.</li>
</ul>
<p><b>Note:</b> Do not create the "empty" files manually in the explorer.</p>
<p><b>Note 2:</b> If the savefile returns an error in-game, reach a save point and create a save slot on the empty savefile before conversion and try again.</p>
</div>
</div>
<div class="save-locations">
Expand Down
60 changes: 60 additions & 0 deletions test/copyHexOffsets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
function areBaseNamesSame(name1, name2) {
const baseName1 = name1.split('.')[0].split('_')[0];
const baseName2 = name2.split('.')[0].split('_')[0];
return baseName1 === baseName2;
}

function copyHexOffsets() {
const fileInput1 = document.getElementById('file1').files[0];
const fileInput2 = document.getElementById('file2').files[0];

if (!fileInput1 || !fileInput2) {
alert("Please select two files.");
return;
}
else if (!areBaseNamesSame(fileInput1.name, fileInput2.name)) {
alert("Savefiles are not of the same game.");
return;
}

const reader1 = new FileReader();
const reader2 = new FileReader();

reader1.onload = function (e1) {
const arrayBuffer1 = e1.target.result;
const uint8Array1 = new Uint8Array(arrayBuffer1);

reader2.onload = function (e2) {
const arrayBuffer2 = e2.target.result;
const uint8Array2 = new Uint8Array(arrayBuffer2);

// Copy bytes at offsets from 00000000 to 00000160
for (let i = 0; i <= 0x160; i++) {
uint8Array1[i] = uint8Array2[i];
}

// Copy bytes at offset 006AB060
const offset = 0x6AB060;
for (let i = 0; i < 4; i++) {
uint8Array1[offset + i] = uint8Array2[offset + i];
}

// Create new file
const blob1 = new Blob([uint8Array1], { type: 'application/octet-stream' });
const downloadUrl = URL.createObjectURL(blob1);

// Trigger download
const a = document.createElement('a');
a.href = downloadUrl;
a.download = fileInput2.name;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(downloadUrl);
};

reader2.readAsArrayBuffer(fileInput2);
};

reader1.readAsArrayBuffer(fileInput1);
}
55 changes: 55 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kingdom Hearts 1.5+2.5 Savefile Converter</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="main-container">
<div class="converter-window">
<h1>Kingdom Hearts 1.5+2.5 Savefile Converter</h1>
<h3>Convert from (put your original savefile here):</h3>
<div class="file-input-wrapper">
<input type="file" id="file1" accept=".png" onchange="updateLabel(this)">
<label for="file1">Select File</label>
</div>
<h3>Convert to (put your empty savefile here):</h3>
<div class="file-input-wrapper">
<input type="file" id="file2" accept=".png" onchange="updateLabel(this)">
<label for="file2">Select File</label>
</div>
<button onclick="copyHexOffsets()">Convert</button>
</div>
<div class="example-window">
<h2>Usage Instructions</h2>
<ul>
<li>For this example, let's assume you want to convert an existing EGS KH2 savefile to Steam. Start a new game on Steam and make sure an empty <b>KHIIFM_WW.png</b> appears in the save location.</li>
<li>After you have located both your EGS savefile and your Steam savefile, put the EGS savefile on top and the Steam one on the bottom.</li>
<li>Press Convert. Your Steam savefile with EGS saveslots should now have been downloaded! Put it where you originally found the Steam savefile and you should be good to go.</li>
<li>If some error appears, make sure to read the error properly. Also make sure your file is not renamed in any way and shows up as the game creates them.</li>
</ul>
<p><b>Note:</b> Do not create the "empty" files manually in the explorer.</p>
<p><b>Note 2:</b> If the savefile returns an error in-game, reach a save point and create a save slot on the empty savefile before conversion and try again.</p>
</div>
</div>
<div class="save-locations">
<h2>Save File Locations</h2>
<p>Savefiles can be found in:</p>
<ul>
<li><b>EGS:</b> Documents\KINGDOM HEARTS HD 1.5+2.5 ReMIX</li>
<li><b>Steam:</b> Documents\My Games\KINGDOM HEARTS HD 1.5+2.5 ReMIX</li>
<li><b>Re:Fined:</b> Documents\Kingdom Hearts</li>
</ul>
</div>
<div class="additional-info">
<h3>This can also be used to convert somebody else's savefile to yours.</h3>
<h3>If you only want to convert an individual save slot rather than the whole file, you can use <a href="https://github.com/Xeeynamo/KingdomSaveEditor/releases/tag/v1.15.5">Kingdom Save Editor</a> instead.</h3>
<h3>If you wish to also carry over your achievements, you can do it manually using <a href="https://github.com/syntax-tm/SteamAchievementManager/releases/latest">Steam Achievement Manager</a>.</h3>
<h4><a href="https://github.com/kh-savefileconverter/kh-savefileconverter.github.io/blob/main/copyHexOffsets.js">This tool doesn't do a lot btw it just copies over hex offsets</a></h4>
</div>
<script src="copyHexOffsets.js"></script>
<script src="updateLabel.js"></script>
</body>
</html>
124 changes: 124 additions & 0 deletions test/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
body {
background: url('https://shared.cloudflare.steamstatic.com/store_item_assets/steam/apps/2552430/page_bg_raw.jpg') no-repeat center center fixed;
background-size: cover;
font-family: 'Trebuchet MS', sans-serif;
color: #ffffff;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
height: 100vh;
}

.main-container {
display: flex;
justify-content: center;
align-items: flex-start;
margin-top: 20px;
}

.converter-window, .example-window {
background: rgba(0, 0, 0, 0.7);
padding: 20px;
border-radius: 15px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
margin: 10px;
}

.converter-window {
text-align: center;
width: 350px;
order: 1;
}

.example-window {
width: 400px;
order: 2;
}

.save-locations {
background: rgba(0, 0, 0, 0.7);
padding: 20px;
border-radius: 15px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
margin-top: 20px;
width: 80%;
max-width: 600px;
text-align: center;
}

h1, h2 {
font-size: 1.5em;
margin-bottom: 20px;
}

h3 {
font-size: 1.2em;
margin: 10px 0;
}

p, ul {
margin: 10px 0;
text-align: left;
}

.file-input-wrapper {
position: relative;
width: 100%;
text-align: center;
margin: 10px auto;
}

.file-input-wrapper input[type="file"] {
display: none;
}

.file-input-wrapper label {
display: inline-block;
padding: 10px 20px;
background-color: #003366;
color: #ffffff;
border-radius: 10px;
cursor: pointer;
font-size: 1em;
}

.file-input-wrapper label:hover {
background-color: #005599;
}

button {
background-color: #003366;
color: #ffffff;
border: none;
padding: 10px 20px;
font-size: 1em;
border-radius: 10px;
cursor: pointer;
margin-top: 20px;
}

button:hover {
background-color: #005599;
}

a {
color: #66ccff;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

.additional-info {
background: rgba(0, 0, 0, 0.7);
padding: 20px;
border-radius: 15px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
margin-top: 20px;
width: 80%;
max-width: 600px;
text-align: center;
}
46 changes: 46 additions & 0 deletions test/updateLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function updateLabel(input) {
const label = input.nextElementSibling;
const fileName = input.files[0].name;

let gameName = '';

if (fileName.includes('KHIII')) {
alert("Kingdom Hearts III savefiles are not supported.");
resetInput(input, label);
return;
} else if (fileName.includes('KH0.2')) {
alert("Kingdom Hearts 0.2 savefiles are not supported.");
resetInput(input, label);
return;
} else if (fileName.includes('KH3DHD')) {
alert("Kingdom Hearts DDD savefiles are not supported.");
resetInput(input, label);
return;
}

if (fileName.includes('KHFM')) {
gameName = 'KH1 (EGS)';
} else if (fileName.includes('KHIIFM')) {
gameName = 'KH2 (EGS)';
} else if (fileName.includes('KHReCoM')) {
gameName = 'KH: Re:COM (EGS)';
} else if (fileName.includes('KHBbSFM')) {
gameName = 'KH: BBS (EGS)';
} else {
gameName = null;
alert("Selected file is not a valid Kingdom Hearts savefile.");
resetInput(input, label);
return;
}

if (fileName.includes('_WW') || fileName.includes('_JP')) {
gameName = gameName.replace('EGS', 'Steam');
}

label.textContent = gameName ? `Selected: ${gameName}` : 'Select File';
}

function resetInput(input, label) {
input.value = ""; // Clear the file input
label.textContent = 'Select File'; // Reset the label
}
2 changes: 1 addition & 1 deletion updateLabel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function updateLabel(input) {
return;
}

if (fileName.includes('_WW')) {
if (fileName.includes('_WW') || fileName.includes('_JP')) {
gameName = gameName.replace('EGS', 'Steam');
}

Expand Down

0 comments on commit 8b96864

Please sign in to comment.