mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 08:39:04 +00:00
Make project setup easier with Maven (#411)
* Remove a bunch of .ideas and class files to see if it makes the setup easier * remove some .idea's and imkls * Remove a ton of .class files * [TASK] Switched to maven instead of gradle * [TASK] Added target to gitignore * Remove ignored files * [TASK] Fixed file_server source * [TASK] Fixed client source * [BUGFIX] Main Class * [BUGFIX] Fixed SLF4J * [TASK] Server Libs cleanup * Update setup guide/debug * Maven cli compile instructions * [TASK] Jar building * Update runServer and runFileServer.sh Co-authored-by: Sandro Coutinho <sandro@farrelltech.org>
This commit is contained in:
@@ -138,7 +138,7 @@ public class GameEngine {
|
||||
shutdownServer = false;
|
||||
}
|
||||
|
||||
public static void main(java.lang.String args[])
|
||||
public static void main(java.lang.String[] args)
|
||||
throws NullPointerException, IOException {
|
||||
System.out.println("Starting game engine..");
|
||||
if (GameConstants.SERVER_DEBUG) {
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
package com.rebotted.console;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.rebotted.GameConstants;
|
||||
import com.rebotted.console.commands.ListPlayers;
|
||||
import com.rebotted.console.commands.Stop;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public class CommandConsole implements Runnable {
|
||||
|
||||
private static CommandConsole cc;
|
||||
private Thread self;
|
||||
private Scanner scanner;
|
||||
// Lazy, not intending to add runtime class loading.
|
||||
private ArrayList<CommandProcessor> cmds = new ArrayList<CommandProcessor>();
|
||||
|
||||
private CommandConsole() {
|
||||
cmds.add(new ListPlayers());
|
||||
cmds.add(new Stop());
|
||||
|
||||
scanner = new Scanner(System.in);
|
||||
cc = this;
|
||||
self = new Thread(cc);
|
||||
self.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Welcome to " + GameConstants.SERVER_NAME + ".");
|
||||
while (true) {
|
||||
System.out.print("> ");
|
||||
String input = null;
|
||||
try {
|
||||
input = scanner.nextLine();
|
||||
String[] splited = input.split("\\s+");
|
||||
if (splited[0].isEmpty()) {
|
||||
System.out.println("Command not recognized. Try 'help'.");
|
||||
continue;
|
||||
}
|
||||
if (splited[0].equalsIgnoreCase("help")) {
|
||||
for (CommandProcessor cmd : cmds) {
|
||||
System.out.println(cmd.help());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (CommandProcessor cmd : cmds) {
|
||||
if (cmd.command(splited)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (NoSuchElementException | NullPointerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CommandConsole getInstance() {
|
||||
if (cc == null) {
|
||||
cc = new CommandConsole();
|
||||
}
|
||||
return cc;
|
||||
}
|
||||
|
||||
}
|
||||
package com.rebotted.console;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.rebotted.GameConstants;
|
||||
import com.rebotted.console.commands.ListPlayers;
|
||||
import com.rebotted.console.commands.Stop;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public class CommandConsole implements Runnable {
|
||||
|
||||
private static CommandConsole cc;
|
||||
private Thread self;
|
||||
private Scanner scanner;
|
||||
// Lazy, not intending to add runtime class loading.
|
||||
private ArrayList<CommandProcessor> cmds = new ArrayList<CommandProcessor>();
|
||||
|
||||
private CommandConsole() {
|
||||
cmds.add(new ListPlayers());
|
||||
cmds.add(new Stop());
|
||||
|
||||
scanner = new Scanner(System.in);
|
||||
cc = this;
|
||||
self = new Thread(cc);
|
||||
self.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
System.out.println("Welcome to " + GameConstants.SERVER_NAME + ".");
|
||||
while (true) {
|
||||
System.out.print("> ");
|
||||
String input = null;
|
||||
try {
|
||||
input = scanner.nextLine();
|
||||
String[] splited = input.split("\\s+");
|
||||
if (splited[0].isEmpty()) {
|
||||
System.out.println("Command not recognized. Try 'help'.");
|
||||
continue;
|
||||
}
|
||||
if (splited[0].equalsIgnoreCase("help")) {
|
||||
for (CommandProcessor cmd : cmds) {
|
||||
System.out.println(cmd.help());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (CommandProcessor cmd : cmds) {
|
||||
if (cmd.command(splited)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (NoSuchElementException | NullPointerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static CommandConsole getInstance() {
|
||||
if (cc == null) {
|
||||
cc = new CommandConsole();
|
||||
}
|
||||
return cc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.rebotted.console;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public interface CommandProcessor {
|
||||
|
||||
public boolean command(String[] cmd);
|
||||
|
||||
public String help();
|
||||
}
|
||||
package com.rebotted.console;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public interface CommandProcessor {
|
||||
|
||||
public boolean command(String[] cmd);
|
||||
|
||||
public String help();
|
||||
}
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
package com.rebotted.console.commands;
|
||||
|
||||
import com.rebotted.console.CommandProcessor;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.game.players.PlayerHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public class ListPlayers implements CommandProcessor {
|
||||
|
||||
@Override
|
||||
public boolean command(String[] cmd) {
|
||||
if (!cmd[0].equalsIgnoreCase("list")) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Currently online: " + PlayerHandler.getPlayerCount());
|
||||
for (Player p : PlayerHandler.players) {
|
||||
System.out.print(p.playerName + ",");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String help() {
|
||||
return "list - lists online players.";
|
||||
}
|
||||
|
||||
}
|
||||
package com.rebotted.console.commands;
|
||||
|
||||
import com.rebotted.console.CommandProcessor;
|
||||
import com.rebotted.game.players.Player;
|
||||
import com.rebotted.game.players.PlayerHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public class ListPlayers implements CommandProcessor {
|
||||
|
||||
@Override
|
||||
public boolean command(String[] cmd) {
|
||||
if (!cmd[0].equalsIgnoreCase("list")) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Currently online: " + PlayerHandler.getPlayerCount());
|
||||
for (Player p : PlayerHandler.players) {
|
||||
System.out.print(p.playerName + ",");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String help() {
|
||||
return "list - lists online players.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
package com.rebotted.console.commands;
|
||||
|
||||
import com.rebotted.GameEngine;
|
||||
import com.rebotted.console.CommandProcessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public class Stop implements CommandProcessor {
|
||||
|
||||
@Override
|
||||
public boolean command(String[] cmd) {
|
||||
if (!cmd[0].equalsIgnoreCase("stop")) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Setting shutdown flag to true...");
|
||||
GameEngine.shutdownServer = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String help() {
|
||||
return "stop - sets GameEngine.shutdownServer to true.";
|
||||
}
|
||||
|
||||
}
|
||||
package com.rebotted.console.commands;
|
||||
|
||||
import com.rebotted.GameEngine;
|
||||
import com.rebotted.console.CommandProcessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RS-Emulators
|
||||
*
|
||||
*/
|
||||
public class Stop implements CommandProcessor {
|
||||
|
||||
@Override
|
||||
public boolean command(String[] cmd) {
|
||||
if (!cmd[0].equalsIgnoreCase("stop")) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Setting shutdown flag to true...");
|
||||
GameEngine.shutdownServer = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String help() {
|
||||
return "stop - sets GameEngine.shutdownServer to true.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
|
||||
import com.everythingrs.hiscores.Hiscores;
|
||||
import org.apache.mina.common.IoSession;
|
||||
import com.rebotted.GameConstants;
|
||||
import com.rebotted.GameEngine;
|
||||
@@ -639,7 +641,7 @@ public abstract class Player {
|
||||
if(GameEngine.ersSecret != null && !GameEngine.ersSecret.equals("") && this.playerRights < 2) {
|
||||
boolean debugMessage = false;
|
||||
System.out.println("Updating highscores for " + this.playerName + "!");
|
||||
com.everythingrs.hiscores.Hiscores.update(GameEngine.ersSecret, "Normal Mode", this.playerName, this.playerRights, this.playerXP, debugMessage);
|
||||
Hiscores.update(GameEngine.ersSecret, "Normal Mode", this.playerName, this.playerRights, this.playerXP, debugMessage);
|
||||
} else {
|
||||
System.out.println("EverythingRS API Disabled, highscores not saved!");
|
||||
}
|
||||
|
||||
@@ -926,6 +926,4 @@ public class Commands implements PacketType {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,196 +1,196 @@
|
||||
package com.rebotted.world.clip;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class RegionFactory {
|
||||
|
||||
private static Region[] regions;
|
||||
|
||||
public static Region[] getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
//GameEngine.getLogger(Region.class).info("Loading region configurations...");
|
||||
try {
|
||||
File f = new File("./data/world/map_index");
|
||||
byte[] buffer = new byte[(int) f.length()];
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream(f));
|
||||
dis.readFully(buffer);
|
||||
dis.close();
|
||||
ByteStream in = new ByteStream(buffer);
|
||||
int size = in.length() / 7;
|
||||
regions = new Region[size];
|
||||
int[] regionIds = new int[size];
|
||||
int[] mapGroundFileIds = new int[size];
|
||||
int[] mapObjectsFileIds = new int[size];
|
||||
boolean[] isMembers = new boolean[size];
|
||||
/**
|
||||
* Seems to be that regions consist of
|
||||
* regionIds (16 bits)
|
||||
* groundFileIds (16 bits)
|
||||
* objectsFileIds (16 bits)
|
||||
* isMembers (8 bits)
|
||||
*/
|
||||
for (int i = 0; i < size; i++) {
|
||||
regionIds[i] = in.getUShort();
|
||||
mapGroundFileIds[i] = in.getUShort();
|
||||
mapObjectsFileIds[i] = in.getUShort();
|
||||
isMembers[i] = in.getUByte() == 0;
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
regions[i] = new Region(regionIds[i], isMembers[i]);
|
||||
}
|
||||
//GameEngine.getLogger(Region.class).info(size + " Regions created.");
|
||||
//GameEngine.getLogger(Region.class).info("Populating regions...");
|
||||
for (int i = 0; i < size; i++) {
|
||||
//GameEngine.getLogger(Region.class).info("Region: " + i + " RegionId: " + regionIds[i] + " ObjectsId: " + mapObjectsFileIds[i]
|
||||
// + " ClippingsId: " + mapGroundFileIds[i]);
|
||||
byte[] file1 = getBuffer(new File("./data/world/map/"
|
||||
+ mapObjectsFileIds[i] + ".gz"));
|
||||
byte[] file2 = getBuffer(new File("./data/world/map/"
|
||||
+ mapGroundFileIds[i] + ".gz"));
|
||||
if (file1 == null || file2 == null) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
loadMaps(regionIds[i], new ByteStream(file1),
|
||||
new ByteStream(file2));
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error loading map region: "
|
||||
+ regionIds[i]);
|
||||
}
|
||||
}
|
||||
//GameEngine.getLogger(Region.class).info("Region configuration done.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regions in runescape are chunks of the map.
|
||||
* They are comprised of 64x64 blocks of x,y positions on 4 possibly height levels (z).
|
||||
*
|
||||
* This code populates those positions.
|
||||
*
|
||||
* @param regionId
|
||||
* @param str1
|
||||
* @param str2
|
||||
*/
|
||||
private static void loadMaps(int regionId, ByteStream str1, ByteStream str2) {
|
||||
int regionX = (regionId >> 8) * 64; // Region ID is bitshifted to get X position
|
||||
int regionY = (regionId & 0xff) * 64; // Region ID is bitshifted and AND'd against 0xff to get Y position
|
||||
int[][][] positionArray = new int[4][64][64];
|
||||
/**
|
||||
* z seems to be the height (map level?) (0 through 3) (I'm told these loop for additional levels)
|
||||
* x seems to be X position (of 64 possible positions)
|
||||
* y seems to be Y position (of 64 possible positions)
|
||||
*/
|
||||
for (int localz = 0; localz < 4; localz++) { // height (z coord)
|
||||
for (int localx = 0; localx < 64; localx++) { // x coord
|
||||
for (int localy = 0; localy < 64; localy++) { // y coord
|
||||
while (true) { // we loop through each position x,y,z
|
||||
int v = str2.getUByte(); //Reading the bytestream, I guess the map is read and loaded bottom to top, left to right.
|
||||
if (v == 0) {
|
||||
break;
|
||||
} else if (v == 1) {
|
||||
str2.skip(1);
|
||||
break;
|
||||
} else if (v <= 49) {
|
||||
str2.skip(1);
|
||||
} else if (v <= 81) {
|
||||
positionArray[localz][localx][localy] = v - 49; // Clipping data is gathered.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Clipping data is validated and added.
|
||||
*/
|
||||
for (int localz = 0; localz < 4; localz++) {
|
||||
for (int localx = 0; localx < 64; localx++) {
|
||||
for (int localy = 0; localy < 64; localy++) {
|
||||
if ((positionArray[localz][localx][localy] & 1) == 1) {
|
||||
int height = localz;
|
||||
if ((positionArray[1][localx][localy] & 2) == 2) {
|
||||
height--;
|
||||
}
|
||||
if (height >= 0 && height <= 3) {
|
||||
//GameEngine.getLogger(Region.class).debug("Adding clipping at x,y " + (regionX + localx) + "," + (regionY + localy) + " at height: " + localz);
|
||||
Region.addClipping(regionX + localx, regionY + localy, height, 0x200000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Object data.
|
||||
*/
|
||||
int objectId = -1;
|
||||
int incr;
|
||||
while ((incr = str1.getUSmart()) != 0) {
|
||||
objectId += incr;
|
||||
int location = 0;
|
||||
int incr2;
|
||||
while ((incr2 = str1.getUSmart()) != 0) {
|
||||
location += incr2 - 1;
|
||||
int objectX = location >> 6 & 0x3f;
|
||||
int objectY = location & 0x3f;
|
||||
int objectHeight = location >> 12;
|
||||
int objectData = str1.getUByte();
|
||||
int type = objectData >> 2;
|
||||
int direction = objectData & 0x3;
|
||||
if (objectX < 0 || objectX >= 64 || objectY < 0 || objectY >= 64) {
|
||||
continue; //Checks the object position is not outside the bounds of a region (0-64)
|
||||
}
|
||||
if ((positionArray[1][objectX][objectY] & 2) == 2) {
|
||||
objectHeight--;
|
||||
}
|
||||
if (objectHeight >= 0 && objectHeight <= 3) {
|
||||
Region.addObject(objectId, regionX + objectX, regionY + objectY, objectHeight,
|
||||
type, direction, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getBuffer(File f) throws Exception {
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
byte[] buffer = new byte[(int) f.length()];
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream(f));
|
||||
dis.readFully(buffer);
|
||||
dis.close();
|
||||
byte[] gzipInputBuffer = new byte[999999];
|
||||
int bufferlength = 0;
|
||||
GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(
|
||||
buffer));
|
||||
do {
|
||||
if (bufferlength == gzipInputBuffer.length) {
|
||||
System.out
|
||||
.println("Error inflating data.\nGZIP buffer overflow.");
|
||||
break;
|
||||
}
|
||||
int readByte = gzip.read(gzipInputBuffer, bufferlength,
|
||||
gzipInputBuffer.length - bufferlength);
|
||||
if (readByte == -1) {
|
||||
break;
|
||||
}
|
||||
bufferlength += readByte;
|
||||
} while (true);
|
||||
byte[] inflated = new byte[bufferlength];
|
||||
System.arraycopy(gzipInputBuffer, 0, inflated, 0, bufferlength);
|
||||
buffer = inflated;
|
||||
if (buffer.length < 10) {
|
||||
return null;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
package com.rebotted.world.clip;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class RegionFactory {
|
||||
|
||||
private static Region[] regions;
|
||||
|
||||
public static Region[] getRegions() {
|
||||
return regions;
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
//GameEngine.getLogger(Region.class).info("Loading region configurations...");
|
||||
try {
|
||||
File f = new File("./data/world/map_index");
|
||||
byte[] buffer = new byte[(int) f.length()];
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream(f));
|
||||
dis.readFully(buffer);
|
||||
dis.close();
|
||||
ByteStream in = new ByteStream(buffer);
|
||||
int size = in.length() / 7;
|
||||
regions = new Region[size];
|
||||
int[] regionIds = new int[size];
|
||||
int[] mapGroundFileIds = new int[size];
|
||||
int[] mapObjectsFileIds = new int[size];
|
||||
boolean[] isMembers = new boolean[size];
|
||||
/**
|
||||
* Seems to be that regions consist of
|
||||
* regionIds (16 bits)
|
||||
* groundFileIds (16 bits)
|
||||
* objectsFileIds (16 bits)
|
||||
* isMembers (8 bits)
|
||||
*/
|
||||
for (int i = 0; i < size; i++) {
|
||||
regionIds[i] = in.getUShort();
|
||||
mapGroundFileIds[i] = in.getUShort();
|
||||
mapObjectsFileIds[i] = in.getUShort();
|
||||
isMembers[i] = in.getUByte() == 0;
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
regions[i] = new Region(regionIds[i], isMembers[i]);
|
||||
}
|
||||
//GameEngine.getLogger(Region.class).info(size + " Regions created.");
|
||||
//GameEngine.getLogger(Region.class).info("Populating regions...");
|
||||
for (int i = 0; i < size; i++) {
|
||||
//GameEngine.getLogger(Region.class).info("Region: " + i + " RegionId: " + regionIds[i] + " ObjectsId: " + mapObjectsFileIds[i]
|
||||
// + " ClippingsId: " + mapGroundFileIds[i]);
|
||||
byte[] file1 = getBuffer(new File("./data/world/map/"
|
||||
+ mapObjectsFileIds[i] + ".gz"));
|
||||
byte[] file2 = getBuffer(new File("./data/world/map/"
|
||||
+ mapGroundFileIds[i] + ".gz"));
|
||||
if (file1 == null || file2 == null) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
loadMaps(regionIds[i], new ByteStream(file1),
|
||||
new ByteStream(file2));
|
||||
} catch (Exception e) {
|
||||
System.out.println("Error loading map region: "
|
||||
+ regionIds[i]);
|
||||
}
|
||||
}
|
||||
//GameEngine.getLogger(Region.class).info("Region configuration done.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Regions in runescape are chunks of the map.
|
||||
* They are comprised of 64x64 blocks of x,y positions on 4 possibly height levels (z).
|
||||
*
|
||||
* This code populates those positions.
|
||||
*
|
||||
* @param regionId
|
||||
* @param str1
|
||||
* @param str2
|
||||
*/
|
||||
private static void loadMaps(int regionId, ByteStream str1, ByteStream str2) {
|
||||
int regionX = (regionId >> 8) * 64; // Region ID is bitshifted to get X position
|
||||
int regionY = (regionId & 0xff) * 64; // Region ID is bitshifted and AND'd against 0xff to get Y position
|
||||
int[][][] positionArray = new int[4][64][64];
|
||||
/**
|
||||
* z seems to be the height (map level?) (0 through 3) (I'm told these loop for additional levels)
|
||||
* x seems to be X position (of 64 possible positions)
|
||||
* y seems to be Y position (of 64 possible positions)
|
||||
*/
|
||||
for (int localz = 0; localz < 4; localz++) { // height (z coord)
|
||||
for (int localx = 0; localx < 64; localx++) { // x coord
|
||||
for (int localy = 0; localy < 64; localy++) { // y coord
|
||||
while (true) { // we loop through each position x,y,z
|
||||
int v = str2.getUByte(); //Reading the bytestream, I guess the map is read and loaded bottom to top, left to right.
|
||||
if (v == 0) {
|
||||
break;
|
||||
} else if (v == 1) {
|
||||
str2.skip(1);
|
||||
break;
|
||||
} else if (v <= 49) {
|
||||
str2.skip(1);
|
||||
} else if (v <= 81) {
|
||||
positionArray[localz][localx][localy] = v - 49; // Clipping data is gathered.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Clipping data is validated and added.
|
||||
*/
|
||||
for (int localz = 0; localz < 4; localz++) {
|
||||
for (int localx = 0; localx < 64; localx++) {
|
||||
for (int localy = 0; localy < 64; localy++) {
|
||||
if ((positionArray[localz][localx][localy] & 1) == 1) {
|
||||
int height = localz;
|
||||
if ((positionArray[1][localx][localy] & 2) == 2) {
|
||||
height--;
|
||||
}
|
||||
if (height >= 0 && height <= 3) {
|
||||
//GameEngine.getLogger(Region.class).debug("Adding clipping at x,y " + (regionX + localx) + "," + (regionY + localy) + " at height: " + localz);
|
||||
Region.addClipping(regionX + localx, regionY + localy, height, 0x200000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Object data.
|
||||
*/
|
||||
int objectId = -1;
|
||||
int incr;
|
||||
while ((incr = str1.getUSmart()) != 0) {
|
||||
objectId += incr;
|
||||
int location = 0;
|
||||
int incr2;
|
||||
while ((incr2 = str1.getUSmart()) != 0) {
|
||||
location += incr2 - 1;
|
||||
int objectX = location >> 6 & 0x3f;
|
||||
int objectY = location & 0x3f;
|
||||
int objectHeight = location >> 12;
|
||||
int objectData = str1.getUByte();
|
||||
int type = objectData >> 2;
|
||||
int direction = objectData & 0x3;
|
||||
if (objectX < 0 || objectX >= 64 || objectY < 0 || objectY >= 64) {
|
||||
continue; //Checks the object position is not outside the bounds of a region (0-64)
|
||||
}
|
||||
if ((positionArray[1][objectX][objectY] & 2) == 2) {
|
||||
objectHeight--;
|
||||
}
|
||||
if (objectHeight >= 0 && objectHeight <= 3) {
|
||||
Region.addObject(objectId, regionX + objectX, regionY + objectY, objectHeight,
|
||||
type, direction, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getBuffer(File f) throws Exception {
|
||||
if (!f.exists()) {
|
||||
return null;
|
||||
}
|
||||
byte[] buffer = new byte[(int) f.length()];
|
||||
DataInputStream dis = new DataInputStream(new FileInputStream(f));
|
||||
dis.readFully(buffer);
|
||||
dis.close();
|
||||
byte[] gzipInputBuffer = new byte[999999];
|
||||
int bufferlength = 0;
|
||||
GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(
|
||||
buffer));
|
||||
do {
|
||||
if (bufferlength == gzipInputBuffer.length) {
|
||||
System.out
|
||||
.println("Error inflating data.\nGZIP buffer overflow.");
|
||||
break;
|
||||
}
|
||||
int readByte = gzip.read(gzipInputBuffer, bufferlength,
|
||||
gzipInputBuffer.length - bufferlength);
|
||||
if (readByte == -1) {
|
||||
break;
|
||||
}
|
||||
bufferlength += readByte;
|
||||
} while (true);
|
||||
byte[] inflated = new byte[bufferlength];
|
||||
System.arraycopy(gzipInputBuffer, 0, inflated, 0, bufferlength);
|
||||
buffer = inflated;
|
||||
if (buffer.length < 10) {
|
||||
return null;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user