Fixed several AI bugs, added log system

- Fixes 0000031: Incap is not working correctly
- NPC AI now considers deathblow values correctly
- AI state transition further debugged
- Pet now follows owner after killing attacker
- Added debug log system
- Cleaned up system console from system.out messages
This commit is contained in:
CharonInferar
2014-07-06 23:47:56 +02:00
parent 7eca666dbe
commit 81a811a425
21 changed files with 612 additions and 118 deletions
+80 -42
View File
@@ -1,6 +1,14 @@
package tools;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import main.NGECore;
@@ -12,61 +20,58 @@ import org.apache.mina.core.buffer.IoBuffer;
public class CharonPacketUtils {
private final static char[] HEX = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
static Path newFile = Paths.get("M:/PSWG/LOGS/PSWG_PacketLog.txt");
private static boolean writeToFile = false;
private CharonPacketLogger logger;
public static String fromLong(long value) {
char[] hexs;
int i;
int c;
hexs = new char[16];
for (i = 0; i < 16; i++) {
c = (int)(value & 0xf);
hexs[16-i-1] = HEX[c];
value = value >> 4;
}
return new String(hexs);
}
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
int v;
for ( int j = 0; j < bytes.length; j++ ) {
v = bytes[j] & 0xFF;
hexChars[j * 2] = hexArray[v >>> 4];
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
public static void createLog(){
try {
Files.deleteIfExists(newFile);
newFile = Files.createFile(newFile);
} catch (IOException ex) {
System.out.println("Error creating file");
}
return new String(hexChars);
System.out.println(Files.exists(newFile));
writeToFile=true;
}
public static String byteToHex(byte bytes) {
char[] hexChars = new char[2];
int v;
v = bytes & 0xFF;
hexChars[2] = hexArray[v >>> 4];
hexChars[2 + 1] = hexArray[v & 0x0F];
return new String(hexChars);
public static void appendToLog(String content, Path newFile){
//Writing to file
try(BufferedWriter writer = Files.newBufferedWriter(
newFile, Charset.defaultCharset(),new OpenOption[] {StandardOpenOption.APPEND})){
writer.append(content);
writer.append("\n");
writer.flush();
}catch(IOException exception){
System.out.println("Error writing to file");
}
}
public static void printAnalysis(IoBuffer pack){
printAnalysis(pack, "");
}
public static void printAnalysis(IoBuffer pack, String packetName){
if (!NGECore.PACKET_DEBUG)
return;
//appendToLog(packetName+" :");
int hexLineNumber = 0;
byte[] packArray = pack.array();
int lineCount = packArray.length/16;
int actualIndex = 0;
String buffString = "";
String asciiString = "";
String logString = packetName+" :\n";
for (int lineIndex = 0; lineIndex <= lineCount; lineIndex++)
{
byte[] ASCIIArray = new byte[16];
for (int x=0;x<16;x++)
ASCIIArray[x] = 32;
buffString = "";
asciiString = "";
// remaining bytes per line
@@ -80,24 +85,57 @@ public class CharonPacketUtils {
buffString += " ";
else buffString += " ";
buffString += ((Integer.toString( ( packArray[actualIndex] & 0xff ) + 0x100, 16).substring( 1 )).toUpperCase() + "");
String addString = ((Integer.toString( ( packArray[actualIndex] & 0xff ) + 0x100, 16).substring( 1 )).toUpperCase() + "");
char character = addString.charAt(0);
if (character==0)
addString = " ";
buffString += addString;
if (packArray[actualIndex] < 31 || packArray[actualIndex] == 13)
ASCIIArray[byteColumnIndex] = 32;
ASCIIArray[byteColumnIndex] = 46;
else
ASCIIArray[byteColumnIndex] = packArray[actualIndex];
if (ASCIIArray[byteColumnIndex]==0)
ASCIIArray[byteColumnIndex]=32;
actualIndex++;
}
try {
asciiString += new String(ASCIIArray, "US-ASCII");
//asciiString += new String(ASCIIArray, "US-ASCII");
asciiString += new String(ASCIIArray, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(buffString + " " + asciiString);
asciiString.replaceAll(" ",".");
String number = Integer.toHexString(hexLineNumber);
if (number.length()<3)
number = "00" + number;
if (number.length()<4)
number = "0" + number;
String lineNumberString = number + ": ";
hexLineNumber += 0x10;
//System.out.println(lineNumberString + buffString + " " + asciiString);
// if (writeToFile)
// appendToLog(lineNumberString + buffString + " " + asciiString);
logString += lineNumberString + buffString + " " + asciiString + "\n";
}
System.out.println("------------------------------------------------------------------------");
logString += "\n";
if (writeToFile){
CharonPacketLogger logger = CharonPacketLogger.getLogger();
logger.log(logString,newFile);
}
//System.out.println("#########################################################################");
System.out.println("");
//if (writeToFile)
// appendToLog("");
}
}