Skip to content

Instantly share code, notes, and snippets.

@ekmillard
Created December 7, 2023 22:27
Show Gist options
  • Save ekmillard/7c5a400050653d69f4ceb37d5164c256 to your computer and use it in GitHub Desktop.
Save ekmillard/7c5a400050653d69f4ceb37d5164c256 to your computer and use it in GitHub Desktop.
package ps.eden.server.cache.editor.leanbow;
import ps.eden.server.ServerConstants;
import ps.eden.server.cache.editor.mgi.tools.rseditor.core.cache.Cache;
import ps.eden.server.cache.editor.mgi.tools.rseditor.core.cache.File;
import ps.eden.server.cache.editor.mgi.tools.rseditor.core.cache.FileSystem;
import ps.eden.server.cache.editor.mgi.tools.rseditor.core.cache.Folder;
import ps.eden.server.cache.editor.mgi.tools.rseditor.core.utilities.ByteBuffer;
public final class OSRSCachePacker {
public static void main(String args[]) {
Cache cache530 = Cache.openCache(ServerConstants.CACHE_530_DIR);
// 498 stuff
Cache cache498 = Cache.openCache(ServerConstants.CACHE_498_DIR);
cache530.createNewIndex(29);
cache530.createNewIndex(28);
cache530.createNewIndex(31);
cache530.createNewIndex(32);
// 29 frames - 0
// 30 frame bases - 1
// 31 models - 7
// 32 sequence - 20
//Pack data
System.out.println("packing 498 frames");
pack(0, 29, cache530, cache498);
System.out.println("packing 498 frame bases");
pack(1, 30, cache530, cache498);
System.out.println("packing 498 models");
pack(7, 31, cache530, cache498);
System.out.println("packing 498 sequence");
pack(20, 32, cache530, cache498);
System.out.println("packing 498 idk");
packConfig(3, cache530, cache498);
// osrs stuff
cache530.createNewIndex(33);
cache530.createNewIndex(34);
cache530.createNewIndex(35);
//33 frames - 0
//34 frame bases - 1
//35 models - 7
Cache cacheOsrs = Cache.openCache(ServerConstants.CACHE_OSRS_DIR);
// if (true) {
// packConfig(35, cache530, cacheOsrs, 45); // map icons?
// int[] ids = {1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1534, 1535, 1461, 1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 1480, 1481, 1482, 1483, 1484, 1485, 1486, 1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1515, 1516, 1517, 1518, 1519, 1520, 1521, 1522, 1523, 1524, 1525, 1526, 1527, 1528, 1529, 1530, 1531, 1532, 1533,};
// for (int id : ids) {
// packSprite(id, cache530, cacheOsrs);
// }
// return;
// }
System.out.println("packing osrs frames");
pack(0, 33, cache530, cacheOsrs);
System.out.println("packing osrs frame bases");
pack(1, 34, cache530, cacheOsrs);
System.out.println("packing osrs models");
pack(7, 35, cache530, cacheOsrs);
/*
public static final int OSRS_OBJ = 36;
public static final int OSRS_SEQ = 38;
public static final int OSRS_NPC = 37;
public static final int OSRS_SPOTANIM = 39;
public static final int OSRS_LOC = 44;
*/
System.out.println("packing osrs items");
packConfig(10, cache530, cacheOsrs, 36);
System.out.println("packing osrs npcs");
packConfig(9, cache530, cacheOsrs, 37);
System.out.println("packing osrs anims");
packConfig(12, cache530, cacheOsrs, 38);
System.out.println("packing osrs gfx");
packConfig(13, cache530, cacheOsrs, 39);
System.out.println("packing osrs maps");
packConfig(6, cache530, cacheOsrs, 44);
System.out.println("packing osrs underlays");
packConfig(1, cache530, cacheOsrs, 46);
System.out.println("packing osrs overlays");
packConfig(4, cache530, cacheOsrs, 47);
}
static void packSprite(int id, Cache cache530, Cache cache498) {
FileSystem fs = cache530.getFilesSystem(8);
FileSystem fs498 = cache498.getFilesSystem(8);
Folder folder = fs.findFolderByID(0).copy();
folder.setID(-1);
folder.deleteAllFiles();
File file = fs498.findFolderByID(id).findFileByID(0);
if (file == null) {
System.out.println("error packing " + id + " sprite.");
return;
}
folder.addFile(file);
folder.recalculate();
fs.addFolder(folder);
System.out.println("lookupMap.put(" + id + "," + folder.getID() + ");");
fs.finish();
}
static void packConfig(int from, Cache cache530, Cache cache498) {
packConfig(from, cache530, cache498, -1);
}
static void packConfig(int from, Cache cache530, Cache cache498, int to) {
FileSystem fs = cache530.getFilesSystem(2);
FileSystem fs498 = cache498.getFilesSystem(2);
Folder folder = fs.findFolderByID(3).copy();
folder.setID(to);
folder.deleteAllFiles();
int highest = 0;
for (int i = 0; i < 100_000; i++) {
File file = fs498.findFolderByID(from).findFileByID(i);
if (file == null) {
continue;
}
file.setID(i);
folder.addFile(file);
if (i > highest) highest = i;
}
folder.recalculate();
fs.addFolder(folder);
System.out.println(folder.getID() + "(highest=" + highest + ")");
fs.finish();
}
static void pack(int from, int to, Cache cache530, Cache cache498) {
for (int i = 0; i < cache498.getFilesStore(from).getFileCount(); i++) {
try {
ByteBuffer data = cache498.getFilesStore(from).get(i);
if (data == null) {
continue;
}
if (!cache530.getFilesStore(to).put(i, data, data.getBuffer().length)) {
System.out.println("2Error on " + i);
}
} catch (Exception e) {
System.out.println("Error on " + i);
e.printStackTrace();
}
}
ByteBuffer data = cache498.getInformationStore().get(from);
if (!cache530.getInformationStore().put(to, data, data.getBuffer().length)) {
System.out.println("fs Error on " + to);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment