diff --git a/src/protocol/swg/FactionResponseMessage.java b/src/protocol/swg/FactionResponseMessage.java index ad9f85e9..fe3b8bbb 100644 --- a/src/protocol/swg/FactionResponseMessage.java +++ b/src/protocol/swg/FactionResponseMessage.java @@ -55,7 +55,13 @@ public class FactionResponseMessage extends SWGMessage { } public IoBuffer serialize() { - IoBuffer result = IoBuffer.allocate(26).order(ByteOrder.LITTLE_ENDIAN); + int size = 26 + (factionStandingMap.size() * 4); + + for (String faction : factionStandingMap.keySet()) { + size += (2 + faction.length()); + } + + IoBuffer result = IoBuffer.allocate(size, false).order(ByteOrder.LITTLE_ENDIAN); result.setAutoExpand(true); result.putShort((short) 2); result.putInt(Opcodes.FactionResponseMessage); @@ -68,10 +74,10 @@ public class FactionResponseMessage extends SWGMessage { } result.putInt(factionStandingMap.size()); for (Integer points : factionStandingMap.values()) { - result.putInt(points); + result.putFloat((float) points); } - - return result.flip(); + result.flip(); + return result; } } diff --git a/src/resources/common/ObjControllerOpcodes.java b/src/resources/common/ObjControllerOpcodes.java index 17c9784c..bd462a73 100644 --- a/src/resources/common/ObjControllerOpcodes.java +++ b/src/resources/common/ObjControllerOpcodes.java @@ -26,8 +26,8 @@ public class ObjControllerOpcodes { public static final int DATA_TRANSFORM = 0x71000000; public static final int DATA_TRANSFORM_WITH_PARENT = 0xF1000000; public static final int COMMAND_QUEUE_ENQUEUE = 0x16010000; - public static final int HOVER_TARGET = 0x26010000; - public static final int TARGET_UPDATE = 0xC5040000; + public static final int HOVER_TARGET = 0x26010000; // lookAtTarget + public static final int TARGET_UPDATE = 0xC5040000; // intendedTarget public static final int OBJECT_MENU_REQUEST = 0x46010000; public static final int SECURE_TRADE = 0x15010000; public static final int BUFF_BUILDER_CHANGE = 0x5A020000; diff --git a/src/resources/common/StringUtilities.java b/src/resources/common/StringUtilities.java index c553f47d..a28bf368 100644 --- a/src/resources/common/StringUtilities.java +++ b/src/resources/common/StringUtilities.java @@ -25,6 +25,8 @@ import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import org.apache.mina.core.buffer.IoBuffer; + public class StringUtilities { final protected static char[] hexArray = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; @@ -33,10 +35,26 @@ public class StringUtilities { return getString(buffer, "US-ASCII"); } + public static String getAsciiString(IoBuffer buffer) { + return getString(buffer, "US-ASCII"); + } + + public static String getAsciiString(IoBuffer buffer, boolean integer) { + return getString(buffer, "US-ASCII", integer); + } + public static String getUnicodeString(ByteBuffer buffer) { return getString(buffer, "UTF-16LE"); } + public static String getUnicodeString(IoBuffer buffer) { + return getString(buffer, "UTF-16LE"); + } + + public static String getUnicodeString(IoBuffer buffer, boolean integer) { + return getString(buffer, "UTF-16LE", integer); + } + public static byte[] getAsciiString(String string) { return getString(string, "US-ASCII"); } @@ -69,6 +87,62 @@ public class StringUtilities { return result; } + private static String getString(IoBuffer buffer, String charFormat) { + String result; + int length; + + if (charFormat == "UTF-16LE") { + length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt(); + } else { + length = buffer.order(ByteOrder.LITTLE_ENDIAN).getShort(); + } + + int bufferPosition = buffer.position(); + + try { + result = new String(buffer.array(), bufferPosition, length, charFormat); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return ""; + } + + buffer.position(bufferPosition + length); + + return result; + } + + private static String getString(IoBuffer buffer, String charFormat, boolean integer) { + String result; + int length; + + if (charFormat == "UTF-16LE") { + if (integer) { + length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt() * 2; + } else { + length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt(); + } + } else { + if (integer) { + length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt(); + } else { + length = buffer.order(ByteOrder.LITTLE_ENDIAN).getShort(); + } + } + + int bufferPosition = buffer.position(); + + try { + result = new String(buffer.array(), bufferPosition, length, charFormat); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + return ""; + } + + buffer.position(bufferPosition + length); + + return result; + } + private static byte[] getString(String string, String charFormat) { ByteBuffer result; int length = 2 + string.length(); diff --git a/src/resources/objects/player/PlayerMessageBuilder.java b/src/resources/objects/player/PlayerMessageBuilder.java index 452acc19..7259f319 100644 --- a/src/resources/objects/player/PlayerMessageBuilder.java +++ b/src/resources/objects/player/PlayerMessageBuilder.java @@ -22,7 +22,6 @@ package resources.objects.player; import java.nio.ByteOrder; -import java.util.BitSet; import java.util.Map.Entry; import org.apache.mina.core.buffer.IoBuffer; diff --git a/src/services/CharacterService.java b/src/services/CharacterService.java index 5298d0da..63550638 100644 --- a/src/services/CharacterService.java +++ b/src/services/CharacterService.java @@ -218,7 +218,7 @@ public class CharacterService implements INetworkDispatch { object.setPosition(new Point3D(3528, 0, -4804)); object.setCashCredits(100); object.setBankCredits(1000); - object.setOptionsBitmask(0x80); + object.setOptionsBitmask(Options.ATTACKABLE); //object.setPosition(new Point3D(0, 0, 0)); object.setOrientation(new Quaternion(1, 0, 0, 0)); object.setLevel((short) 1); diff --git a/src/services/gcw/FactionService.java b/src/services/gcw/FactionService.java index ee1122c6..55f7a17a 100644 --- a/src/services/gcw/FactionService.java +++ b/src/services/gcw/FactionService.java @@ -39,8 +39,6 @@ import resources.common.Opcodes; import resources.objects.creature.CreatureObject; import resources.objects.player.PlayerObject; -import engine.clientdata.ClientFileManager; -import engine.clientdata.visitors.DatatableVisitor; import engine.clients.Client; import engine.resources.common.CRC; import engine.resources.service.INetworkDispatch; @@ -53,22 +51,22 @@ public class FactionService implements INetworkDispatch { private Map factionMap = new TreeMap(); public FactionService(NGECore core) { - DatatableVisitor factionTable; - this.core = core; try { - factionTable = ClientFileManager.loadFile("strings/en/faction/faction_names.stf", DatatableVisitor.class); + /* Temporarily commented until another commit + StfTable stf = new StfTable("string/en/faction/faction_names.stf"); - for (int s = 0; s < factionTable.getRowCount(); s++) { - if (factionTable.getObject(s, 0) != null) { - String faction = ((String) factionTable.getObject(s, 1)); + for (int s = 1; s < strings.length; s++) { + if (strings[0] != null) { + String faction = ((String) strings[s][0]); factionMap.put(faction, CRC.StringtoCRC(faction)); } } - } catch (Exception e) { - e.printStackTrace(); - } + */ + } catch (Exception e) { + e.printStackTrace(); + } } public int getCRC(String faction) {