Skip to content

Commit 2f4ecbb

Browse files
committed
Removed dependence of ngeengine_public.jar
1 parent 6aa55b9 commit 2f4ecbb

File tree

4 files changed

+222
-4
lines changed

4 files changed

+222
-4
lines changed

.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5-
<classpathentry kind="lib" path="libs/ngengine_public.jar"/>
65
<classpathentry kind="lib" path="libs/mina-core-2.0.4.jar"/>
76
<classpathentry kind="output" path="bin"/>
87
</classpath>

src/com/projectswg/tools/stf/StfSearcher.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import javax.swing.JPanel;
3030
import javax.swing.JTextPane;
3131

32-
import engine.clientdata.StfTable;
33-
import engine.clientdata.StfTable.Pair;
34-
3532
import java.awt.BorderLayout;
3633
import java.io.File;
3734
import java.io.IOException;
@@ -46,6 +43,8 @@
4643
import javax.swing.JScrollPane;
4744
import javax.swing.JCheckBox;
4845

46+
import com.projectswg.tools.stf.StfTable.Pair;
47+
4948
public class StfSearcher {
5049

5150
private static StfSearcher searcher;
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*******************************************************************************
2+
* Part of NGECore2
3+
* Copyright (c) 2013 <Project SWG>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
******************************************************************************/
19+
package com.projectswg.tools.stf;
20+
21+
import java.io.IOException;
22+
import java.nio.ByteOrder;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
26+
import org.apache.mina.core.buffer.IoBuffer;
27+
28+
/*
29+
* Stf files don't appear to use the IFF format.
30+
*
31+
* ID 0 will probably always be null because they start at 1.
32+
*/
33+
public class StfTable {
34+
35+
private String[][] orderedTable;
36+
private List<Pair<String, String>> disorderedTable;
37+
38+
public class Pair<K, V> {
39+
40+
private K key;
41+
private V value;
42+
43+
public Pair(K key, V value) {
44+
this.key = key;
45+
this.value = value;
46+
}
47+
48+
public K getKey() {
49+
return key;
50+
}
51+
52+
public V getValue() {
53+
return value;
54+
}
55+
56+
}
57+
58+
public StfTable() {
59+
60+
}
61+
62+
public StfTable(String filePath) throws IOException {
63+
readFile(filePath);
64+
}
65+
66+
public void readFile(String filePath) throws IOException {
67+
java.io.FileInputStream stf = new java.io.FileInputStream(filePath);
68+
69+
IoBuffer buffer = IoBuffer.allocate(stf.available(), false);
70+
71+
buffer.setAutoExpand(true);
72+
buffer.order(ByteOrder.LITTLE_ENDIAN);
73+
74+
byte[] buf = new byte[1024];
75+
76+
for (int i = stf.read(buf); i != -1; i = stf.read(buf)) {
77+
buffer.put(buf, 0, i);
78+
}
79+
80+
buffer.flip();
81+
82+
buffer.getInt(); // Size?
83+
84+
buffer.get(); // isMore?
85+
86+
int arrayCount = buffer.getInt();
87+
88+
int rowCount = buffer.getInt();
89+
90+
orderedTable = new String[arrayCount][2];
91+
disorderedTable = new ArrayList<Pair<String, String>>();
92+
93+
for (int i = 0; i < rowCount; i++) {
94+
int id = buffer.getInt();
95+
buffer.getInt();
96+
String value = "";
97+
value = StringUtilities.getUnicodeString(buffer, true);
98+
orderedTable[id][0] = null;
99+
orderedTable[id][1] = value;
100+
}
101+
102+
for (int i = 0; i < rowCount; i++) {
103+
int id = buffer.getInt();
104+
String name = StringUtilities.getAsciiString(buffer, true);
105+
orderedTable[id][0] = name;
106+
disorderedTable.add(new Pair<String, String>(name, orderedTable[id][1]));
107+
}
108+
109+
stf.close();
110+
}
111+
112+
public int getRowCount() {
113+
return ((orderedTable == null) ? 0 : orderedTable.length);
114+
}
115+
116+
public int getColumnCount() {
117+
return ((orderedTable == null) ? 0 : 3);
118+
}
119+
120+
/*
121+
* @param id Iteration number
122+
*
123+
* @returns String's key-value pair from an alphanumeric list
124+
*/
125+
public Pair<String, String> getString(int id) {
126+
return disorderedTable.get(id);
127+
}
128+
129+
/*
130+
* @param id Identifying number of the string from the .stf file, unlike above
131+
*
132+
* @returns String's key-value pair from an unordered list
133+
*/
134+
public Pair<String, String> getStringById(int id) {
135+
return new Pair<String, String>(orderedTable[id][0], orderedTable[id][1]);
136+
}
137+
138+
/*
139+
* @param name Name of the string to return
140+
*
141+
* @returns The value for this key, or null if the key is not found
142+
*/
143+
public String getString(String name) {
144+
for (String[] columns : orderedTable) {
145+
if (columns[0].equals(name)) {
146+
return columns[1];
147+
}
148+
}
149+
150+
return null;
151+
}
152+
153+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*******************************************************************************
2+
* Part of NGECore2
3+
* Copyright (c) 2013 <Project SWG>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
******************************************************************************/
19+
package com.projectswg.tools.stf;
20+
21+
import java.io.UnsupportedEncodingException;
22+
import java.nio.ByteOrder;
23+
24+
import org.apache.mina.core.buffer.IoBuffer;
25+
26+
public class StringUtilities {
27+
28+
public static String getUnicodeString(IoBuffer buffer, boolean integer) {
29+
return getString(buffer, "UTF-16LE", integer);
30+
}
31+
32+
public static String getAsciiString(IoBuffer buffer, boolean integer) {
33+
return getString(buffer, "US-ASCII", integer);
34+
}
35+
36+
private static String getString(IoBuffer buffer, String charFormat, boolean integer) {
37+
String result;
38+
int length;
39+
40+
if (charFormat.equals("UTF-16LE")) {
41+
if (integer) {
42+
length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt() * 2;
43+
} else {
44+
length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt();
45+
}
46+
} else {
47+
if (integer) {
48+
length = buffer.order(ByteOrder.LITTLE_ENDIAN).getInt();
49+
} else {
50+
length = buffer.order(ByteOrder.LITTLE_ENDIAN).getShort();
51+
}
52+
}
53+
54+
int bufferPosition = buffer.position();
55+
56+
try {
57+
result = new String(buffer.array(), bufferPosition, length, charFormat);
58+
} catch (UnsupportedEncodingException e) {
59+
e.printStackTrace();
60+
return "";
61+
}
62+
63+
buffer.position(bufferPosition + length);
64+
65+
return result;
66+
}
67+
}

0 commit comments

Comments
 (0)