I have an application which is instrumented into an old game (java 7) and I'm turning the objects I get through reflection to XML using XStream because its the only library that can handle circular references.
When trying to turn objects into XML, it works wonderfully but when trying to turn the XML into an Object it returns a com.thoughtworks.xstream.mapper.CannotResolveClassException
error.
I can't add the alias tag to the object classes as I can't edit them (if you notice, I get the objects using the Reflection API).
Code to get XML and turn to Object:
XStream x = new XStream();
x.setMode(XStream.XPATH_RELATIVE_REFERENCES);
x.addPermission(NoTypePermission.NONE);
x.addPermission(NullPermission.NULL);
x.addPermission(PrimitiveTypePermission.PRIMITIVES);
x.allowTypeHierarchy(Collection.class);
x.allowTypes(reflector.getInst().getAllLoadedClasses());
Object[] o = (Object[])reflector.getFieldValue(loc,null);
for(Object n : o) {
if(n != null) {
String xml = x.toXML(n); //from Object to XML
Object nob = x.fromXML(xml,n.getClass()); //from XML to Object
return xml;
}
}
XML file from the Object (ca is the obfuscated name to the Object):
<ca>
<cm>0</cm>
<cq>0</cq>
<cu>-2097798132</cu>
<at>false</at>
<av>-425064064</av>
<ar>777616384</ar>
<ay>false</ay>
<cn>0</cn>
<az>-231471967</az>
<by>0</by>
<au>-1823843303</au>
<ai>419640763</ai>
<aw>-322787699</aw>
<ag>-637134775</ag>
<aq>1800663181</aq>
<bg>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
</bg>
<an>828893911</an>
<bm>0</bm>
<ax>1189585760</ax>
<as>0</as>
<aj>0</aj>
<ae>0</ae>
<ap>0</ap>
<bp>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
</bp>
<bb>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
</bb>
<ak>895202236</ak>
<ci>0</ci>
<af>2091800960</af>
<bc>
<f>
<cm>0</cm>
<cb reference=".."/>
<ct reference=".."/>
</f>
</bc>
<bj>1908800807</bj>
<bl>false</bl>
<bn>-1580866307</bn>
<bo>-2130230028</bo>
<be>115529683</be>
<bw>0</bw>
<bt>-871806267</bt>
<ad>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
</ad>
<bz>0</bz>
<cf>-1364269202</cf>
<ah>-1384145226</ah>
<bv>1496887875</bv>
<br>0</br>
<bs>0</bs>
<bd>0</bd>
<bh>0</bh>
<bk>0</bk>
<bx>0</bx>
<bi>0</bi>
<bu>0</bu>
<bf>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
</bf>
<bq>0</bq>
<ce>0</ce>
<cs>0</cs>
<cg>-990687132</cg>
<cp>1744108544</cp>
<cc>0</cc>
<cl>2083639520</cl>
<aa>false</aa>
<cy>
<int>42</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
</cy>
<cx>
<int>68</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
<int>0</int>
</cx>
<ca>AAAAAAAAAAAAAA==</ca>
<ba>-1741793111</ba>
<cw>0</cw>
<f>
<cm>2794</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd class="jn">
<cm>2792</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd class="jn">
<cm>2790</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd class="jn">
<cm>3033</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd class="jn">
<cm>2793</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd>
<cm>0</cm>
<cq>0</cq>
<cd class="jn">
<cm>3032</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd class="jn">
<cm>3031</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd class="jn">
<cm>1172</cm>
<cb class="jn">
<cm>4628</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct class="jn" reference="../.."/>
<cq>0</cq>
<cd class="jn">
<cm>2791</cm>
<cb>
<cm>0</cm>
<cb class="jn" reference="../.."/>
<ct class="jn" reference="../.."/>
</cb>
<ct reference="../cb"/>
<cq>0</cq>
<cd class="jn" reference="../../../../../../../../../../.."/>
<cj class="jn" reference="../.."/>
<k>454184410</k>
<z>1657047109</z>
<q>Cow</q>
<t>1748512828</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>-106542840</n>
<h>1868532352</h>
<c>
<int>23895</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>-1845419392</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>0</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<ak>false</ak>
</cd>
<cj class="jn" reference="../.."/>
<k>227092205</k>
<z>1673567484</z>
<q>Gillie Groats</q>
<u>
<int>114</int>
<int>136</int>
</u>
<t>2077080606</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>1172779207</n>
<h>1868532352</h>
<c>
<int>391</int>
<int>417</int>
<int>467</int>
<int>14588</int>
<int>10706</int>
<int>11119</int>
<int>358</int>
<int>14794</int>
</c>
<v>
<string>Talk-to</string>
<null/>
<null/>
<null/>
<null/>
</v>
<y>
<short>908</short>
<short>532</short>
<short>536</short>
<short>412</short>
<short>417</short>
<short>8741</short>
</y>
<r>1665957021</r>
<d>true</d>
<a>0</a>
<g>-1845419392</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>0</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<s>
<short>-31864</short>
<short>-31860</short>
<short>-31984</short>
<short>-32236</short>
<short>-32232</short>
<short>-32356</short>
</s>
<ak>false</ak>
</cb>
<ct reference="../cb/cb"/>
<cq>0</cq>
<cd class="jn" reference="../cb"/>
<cj class="jn" reference="../.."/>
<k>227092205</k>
<z>835865724</z>
<q></q>
<t>-695331945</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>875462989</n>
<h>1868532352</h>
<c>
<int>8236</int>
</c>
<v>
<null/>
<null/>
<null/>
<null/>
<null/>
</v>
<r>1665957021</r>
<d>true</d>
<a>0</a>
<g>-1845419392</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>0</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<ak>false</ak>
</cd>
<cj class="jn" reference="../.."/>
<k>227092205</k>
<z>-253305835</z>
<q>Goblin</q>
<u>
<int>24209</int>
</u>
<t>-1415511251</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>1297520940</n>
<h>141136344</h>
<c>
<int>24455</int>
<int>24482</int>
<int>24432</int>
<int>24474</int>
<int>24441</int>
<int>24448</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<y>
<short>6040</short>
<short>6323</short>
<short>6331</short>
</y>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>954273880</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>-1042177293</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<s>
<short>5795</short>
<short>5010</short>
<short>6038</short>
</s>
<ak>false</ak>
</cd>
<cj reference="../.."/>
<k>227092205</k>
<z>1063015944</z>
<q>Goblin</q>
<u>
<int>24211</int>
</u>
<t>-1415511251</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>1297520940</n>
<h>-920844118</h>
<c>
<int>24458</int>
<int>24486</int>
<int>24432</int>
<int>24475</int>
<int>24441</int>
<int>24448</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<y>
<short>11941</short>
<short>12060</short>
</y>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>-397859062</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>-1042177293</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<s>
<short>17839</short>
<short>17959</short>
</s>
<ak>false</ak>
</cd>
<cj class="jn" reference="../.."/>
</cd>
<cj class="jn" reference="../.."/>
<k>454184410</k>
<z>-5276629</z>
<q>Cow</q>
<t>1748512828</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>-106542840</n>
<h>1868532352</h>
<c>
<int>23893</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>-1845419392</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>0</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<ak>false</ak>
</cd>
<cj class="jn" reference="../.."/>
<k>227092205</k>
<z>-1915629573</z>
<q>Goblin</q>
<u>
<int>24217</int>
</u>
<t>-1415511251</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>1297520940</n>
<h>252038935</h>
<c>
<int>24465</int>
<int>24483</int>
<int>24432</int>
<int>24476</int>
<int>24441</int>
<int>24449</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<y>
<short>11941</short>
<short>12060</short>
</y>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>-1169352921</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>-1042177293</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<s>
<short>14656</short>
<short>14775</short>
</s>
<ak>false</ak>
</cd>
<cj class="jn" reference="../.."/>
<k>454184410</k>
<z>340725330</z>
<q>Cow</q>
<t>1748512828</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>-106542840</n>
<h>1868532352</h>
<c>
<int>23889</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>-1845419392</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>0</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<ak>false</ak>
</cd>
<cj class="jn" reference="../.."/>
<k>454184410</k>
<z>-1321598408</z>
<q>Cow calf</q>
<t>1748512828</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>1479687840</n>
<h>-349519468</h>
<c>
<int>23890</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>1972410964</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>0</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<ak>false</ak>
</cd>
<cj class="jn" reference="../cd/cd/cd/cd/cd/cd/cd/cd/cb/cd"/>
<k>454184410</k>
<z>1311045150</z>
<q>Cow calf</q>
<t>1748512828</t>
<e>-1325528541</e>
<o>-466607655</o>
<n>1479687840</n>
<h>-349519468</h>
<c>
<int>23890</int>
</c>
<v>
<null/>
<string>Attack</string>
<null/>
<null/>
<null/>
</v>
<r>1665957021</r>
<d>true</d>
<a>-722371738</a>
<g>1972410964</g>
<p>-885648213</p>
<x>-333349537</x>
<ab>0</ab>
<ac>0</ac>
<ao>-1163470645</ao>
<af>-1127860768</af>
<ah>true</ah>
<ar>-549456829</ar>
<ay>-144903619</ay>
<i>false</i>
<az>true</az>
<ak>false</ak>
</f>
</ca>
The Object has 1 field called "Composite" which returns the object definition (name, basic fields). The Object has a superclass which has circular references.
Here are wrappers that I made a while ago for the objects so you guys can get a better idea on what the object contains:
The Object Itself (NPC) :
public class NPC extends Model {
//The Class itself contains 1 field which is "Composite"
public NPC(Object object) {
super(object);
}
public NPCComposite getComposite() {
return new NPCComposite(getFieldValue("Npc.composite", object));
}
}
The Object above contains only 1 Field and it's "Composite", here's the wrapper for NPCComposite:
public class NPCComposite extends Wrapper {
//Contains 3 Fields: String[], String, int (Nothing out of the ordinary)
public NPCComposite(Object object) {
super(object);
}
public String[] getActions() {
return (String[]) getFieldValue("NpcComposite.actions", object);
}
public int getID() {
return (int) getFieldValue("NpcComposite.id", object);
}
public String getName() {
return (String) getFieldValue("NpcComposite.name", object);
}
}
If you have noticed, the Object itself (NPC) has a superclass, this is the superclass's wrapper: I have added a comment next to field getters that have unapparent return types.
public class Model extends Render {
public Model(Object object) {
super(object);
}
public int getFineX() {
return (int) getFieldValue("Model.localX", object);
}
public int getFineY() {
return (int) getFieldValue("localY", object);
}
public int getAnimation() {
return (int) getFieldValue("animation", object);
}
public int getAnimationDelay() {
return (int) getFieldValue("animationDelay", object);
}
public int getCombatTime() {
return (int) getFieldValue("combatTime", object);
}
public int getStandAnimation() {
return (int) getFieldValue("standAnimation", object);
}
public int getFrameOne() {
return (int) getFieldValue("frameOne", object);
}
public int getFrameTwo() {
return (int) getFieldValue("Model.frameTwo", object);
}
public Object getHealthBars() { //Returns a Health Bar Object
return getFieldValue("Model.healthBars", object);
}
public Object getHitCycles() { //Returns an Integer 1D Array
return getFieldValue("Model.hitCycles", object);
}
public Object getHitDamages() { //Returns an Integer 1D Array
return getFieldValue("Model.hitDamages", object);
}
public Object getHitTypes() { //Returns an Integer 1D Array
return getFieldValue("Model.hitTypes", object);
}
public int getInteracting() {
return (int) getFieldValue("Model.interacting", object);
}
public Object getMessage() { //Returns a String
return getFieldValue("Model.message", object);
}
public int getOrientation() {
return (int) getFieldValue("Model.orientation", object);
}
public int getQueueSize() {
return (int) getFieldValue("Model.queueSize", object);
}
public Object getQueueTraversed() { //Returns a byte 1D array
return getFieldValue("Model.queueTraversed", object);
}
public Object getQueueX() { //Returns a 1D int array
return getFieldValue("Model.queueX", object);
}
public Object getQueueY() { //Returns a 1D int array
return getFieldValue("Model.queueY", object);
}
public int getRuntimeAnimation() {
return (int) getFieldValue("Model.runtimeAnimation", object);
}
}
Any Help will be appreciated!
Thank you!
Aucun commentaire:
Enregistrer un commentaire