Skip to content

Commit 8bf55ca

Browse files
Merge pull request #402 from SWG-Source/feature/developer-content-utilities
Added developer utility commands for object and zone/content inspection. Commands added: - objinfo - zoneutil Both commands include help. To use them, attach the following scripts to your character: - script.developer.obj_information - script.developer.zone_utility The character must be in god mode. The scripts will not attach or function otherwise. These tools are intended to help developers and content creators inspect object data, locations, cells, scenes, transforms, buildout information, objvars, scriptvars, attached scripts, CRCs, and related diagnostic data.
2 parents 0cfaf0c + 5b1baae commit 8bf55ca

3 files changed

Lines changed: 872 additions & 0 deletions

File tree

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
package script.developer;
2+
3+
import script.*;
4+
import script.library.*;
5+
6+
import java.util.*;
7+
8+
public class obj_information_utility extends script.base_script {
9+
10+
11+
//Dictionary Constants
12+
public static final String DICT_OBJ_ID = "ObjectId";
13+
public static final String DICT_OBJ_TYPE = "ObjectType";
14+
public static final String DICT_OBJ_NAME = "DisplayName";
15+
public static final String DICT_OBJ_SERVER_TEMPLATE_NAME = "ServerTemplateName";
16+
public static final String DICT_OBJ_SHARED_TEMPLATE_NAME = "SharedTemplateName";
17+
public static final String DICT_OBJ_CRC = "CRC";
18+
19+
//Object Type Constants
20+
public static final int OBJ_TYPE_UNKNOWN = -1;
21+
public static final int OBJ_TYPE_OBJECT = 0;
22+
public static final int OBJ_TYPE_PLAYER = 2;
23+
24+
public obj_information_utility()
25+
{
26+
}
27+
28+
29+
//Returns the target if it is valid, self if target is invalid and
30+
//self is valid, otherwise a obj_id.NULL_ID
31+
//self: obj_id of self
32+
//target: obj_id of self's target
33+
public static obj_id getTargetOrSelf(obj_id self, obj_id target) throws InterruptedException
34+
{
35+
36+
if (isValidId(target))
37+
{
38+
return target;
39+
}
40+
41+
if (isValidId(self))
42+
{
43+
return self;
44+
}
45+
46+
return obj_id.NULL_ID;
47+
}
48+
49+
//Gets information on the object and stores it in the returned dictionary
50+
//obj: The obj_id to get information for
51+
public static dictionary getObjectInformation(obj_id obj) throws InterruptedException
52+
{
53+
dictionary dict = new dictionary();
54+
getObjectInformation(obj, dict);
55+
return dict;
56+
}
57+
58+
//Gets information on the object and stores it in the provided dictionary
59+
//obj: The obj_id to get information for
60+
//dict: The dictionary to the data in
61+
public static void getObjectInformation(obj_id obj, dictionary dict) throws InterruptedException
62+
{
63+
boolean isPlayer = false;
64+
65+
dict.put(DICT_OBJ_ID, obj);
66+
dict.put(DICT_OBJ_NAME, getName(obj));
67+
68+
if (isPlayer(obj))
69+
{
70+
dict.put(DICT_OBJ_TYPE, OBJ_TYPE_PLAYER);
71+
}
72+
else
73+
{
74+
75+
String sharedTemplateName = getSharedObjectTemplateName(obj);
76+
77+
dict.put(DICT_OBJ_TYPE, OBJ_TYPE_OBJECT);
78+
dict.put(DICT_OBJ_SERVER_TEMPLATE_NAME, getTemplateName(obj));
79+
dict.put(DICT_OBJ_SHARED_TEMPLATE_NAME, sharedTemplateName);
80+
dict.put(DICT_OBJ_CRC, getStringCrc(sharedTemplateName));
81+
}
82+
}
83+
84+
public int cmdObjectInfo(obj_id self, obj_id target, String params, float defaultTime) throws InterruptedException
85+
{
86+
if (!isGod(self))
87+
{
88+
sendSystemMessage(self, "\\#ff0000You do not authorized to use this script.\\#ffffff", null);
89+
}
90+
91+
obj_id infoTarget = null;
92+
93+
StringTokenizer st = new java.util.StringTokenizer(params);
94+
int tokens = st.countTokens();
95+
String objIdString = "";
96+
97+
if (st.hasMoreTokens())
98+
{
99+
objIdString = st.nextToken();
100+
}
101+
102+
if (objIdString != null && objIdString.length() > 0)
103+
{
104+
try
105+
{
106+
infoTarget = obj_id.getObjId(Long.parseLong(objIdString));
107+
}
108+
catch(Exception ex)
109+
{
110+
infoTarget = self;
111+
}
112+
}
113+
114+
if (!isValidId(infoTarget))
115+
{
116+
infoTarget = self;
117+
}
118+
119+
//now pull the data
120+
121+
StringBuilder sb = new StringBuilder();
122+
123+
GetPlayerInformation(infoTarget, sb);
124+
GetObjectInformation(infoTarget, sb);
125+
GetObjVars(infoTarget, sb);
126+
GetScriptVars(infoTarget, sb);
127+
GetScripts(infoTarget, sb);
128+
129+
int pid = sui.msgbox(self, self, sb.toString(), sui.OK_ONLY, "Object Information", sui.MSG_INFORMATION, "noHandler");
130+
setSUIProperty(pid, "Prompt.lblPrompt", "Editable", "true");
131+
setSUIProperty(pid, "Prompt.lblPrompt", "GetsInput", "true");
132+
flushSUIPage(pid);
133+
134+
return SCRIPT_CONTINUE;
135+
}
136+
137+
138+
private static void GetObjVars(obj_id target, StringBuilder sb) throws InterruptedException
139+
{
140+
141+
String packedObjVars = getPackedObjvars(target);
142+
sb.append("\\#FFFFFF======Obj Vars======\\#FFFFFF\n");
143+
144+
String[] strSplit = split(packedObjVars, '|');
145+
if (strSplit.length > 2)
146+
{
147+
for (int intI = 0; intI < strSplit.length - 2; intI++)
148+
{
149+
sb.append("\\#00FF00");
150+
sb.append(strSplit[intI]);
151+
sb.append("=");
152+
sb.append("\\#FFFFFF");
153+
sb.append(strSplit[intI + 2]);
154+
sb.append("\n\r");
155+
intI = intI + 2;
156+
}
157+
}
158+
}
159+
160+
private static void GetScriptVars(obj_id target, StringBuilder sb) throws InterruptedException
161+
{
162+
deltadictionary scriptVars = target.getScriptVars();
163+
Enumeration keys = scriptVars.keys();
164+
sb.append("\\#FFFFFF=====Script Vars=====\\#FFFFFF\n");
165+
166+
while (keys.hasMoreElements())
167+
{
168+
String key = (String)keys.nextElement();
169+
sb.append("\\#00FF00");
170+
sb.append(key);
171+
sb.append("=");
172+
sb.append("\\#FFFFFF");
173+
sb.append(scriptVars.getObject(key).toString());
174+
sb.append("\n");
175+
}
176+
}
177+
178+
private static void GetScripts(obj_id target, StringBuilder sb) throws InterruptedException
179+
{
180+
sb.append("\\#FFFFFF=======Scripts=======\\#FFFFFF\n");
181+
String[] scriptList = getScriptList(target);
182+
183+
for (String script : scriptList)
184+
{
185+
sb.append("\\#00FF00");
186+
sb.append(script);
187+
sb.append("\\#FFFFFF");
188+
sb.append("\n");
189+
}
190+
}
191+
192+
private static void GetPlayerInformation(obj_id target, StringBuilder sb)
193+
{
194+
if (isPlayer(target))
195+
{
196+
sb.append("\\#00FFFFPlayer: \\#FFFFFF");
197+
sb.append(getName(target) );
198+
sb.append("\\#00FF00 (");
199+
sb.append(target.toString());
200+
sb.append("\\)\\#FFFFFF");
201+
sb.append("\n");
202+
}
203+
}
204+
205+
private static void GetObjectInformation(obj_id target, StringBuilder sb)
206+
{
207+
if (!isPlayer(target))
208+
{
209+
sb.append("\\#00FFFFDetails for object id: \\#FFFFFF");
210+
sb.append(target.toString());
211+
sb.append("\n");
212+
String serverTemplateName = getTemplateName(target);
213+
String sharedTemplateName = getSharedObjectTemplateName(target);
214+
int crc = getStringCrc(sharedTemplateName);
215+
String displayName = getName(target);
216+
217+
sb.append("\\#00FFFFServer Template: \\#FFFFFF");
218+
sb.append(serverTemplateName);
219+
sb.append("\n");
220+
sb.append("\\#00FFFFShared Template: \\#FFFFFF");
221+
sb.append(sharedTemplateName);
222+
sb.append("\n");
223+
sb.append("\\#00FFFFDisplay Name: \\#FFFFFF");
224+
sb.append(displayName);
225+
sb.append("\n");
226+
sb.append("\\#00FFFFGame Object Type: \\#FFFFFF");
227+
sb.append(getGameObjectTypeName(getGameObjectType(target)));
228+
sb.append("\n");
229+
sb.append("\\#00FFFFCRC: \\#FFFFFF");
230+
sb.append(Integer.toString(crc));
231+
sb.append("\n");
232+
}
233+
}
234+
235+
236+
237+
}

0 commit comments

Comments
 (0)