Skip to content

Instantly share code, notes, and snippets.

@RealTrisT
Last active October 7, 2017 17:35
Show Gist options
  • Save RealTrisT/da815a84f0b1065411b090557fbd6280 to your computer and use it in GitHub Desktop.
Save RealTrisT/da815a84f0b1065411b090557fbd6280 to your computer and use it in GitHub Desktop.
Reclass XML Files Parser To c++ Structs
<!--
I created this because the one in actual ReClass Is sort of broken when it comes to custom types and classes.
Also because I didn't notice ReClass didn't actually have that feature until I was done with this.
Anyway, open the xml file, ctrl+a -> ctrl+c, and ctrl+v on the text box.
Hope this helps. Have a nice one.
-->
<!DOCTYPE html>
<html>
<head>
<title>Reclass To Struct</title>
<script type="text/javascript">
function findInString(string, character, startAt){
for (var c = startAt; c < string.length; c++) {
if(string[c] == character)return c;
}
return -1;
}
function GetAttribute(string, attribute){
var result = string.substring(string.indexOf(" " + attribute + "=\"")+attribute.length+3, findInString(string, '"', string.indexOf(" " + attribute + "=\"")+attribute.length+3));
return (Number.isNaN(result))?(-1):(result);
}
function doWork(){
//----------------------------------------------------------------------definition
var LineArray = document.getElementById("ReclassXML").value.split('\n');
var SizeBuffer = 0;
var FinalResult = "";
var OffsetBuffer = 0;
//---------------------------------------------------------------------------start
for (var i = 0; i < LineArray.length; i++) {
//------------------------------------------------------------LOOPTHROUGHLINES\
if(LineArray[i].indexOf("<Node Name=\"") != -1){
var Name = "";
var Type = "";
var Skip = false;
var isBuffer = false;
Type = GetAttribute(LineArray[i], "Type");
switch(parseInt(Type)){
case 1:
Type = GetAttribute(LineArray[i], "Instance");
break;
case 4:
isBuffer = true;
SizeBuffer+=4;
break;
case 5:
isBuffer = true;
SizeBuffer+=8;
break;
case 6:
isBuffer = true;
SizeBuffer+=2;
case 7:
isBuffer = true;
SizeBuffer+=1;
break;
case 8:
Type = GetAttribute(LineArray[i], "Pointer")+"*";
break;
case 9:
Type = "short int"
break;
case 10:
Type = "int";
break;
case 11:
Type = "long long int";
break;
case 12:
Type = "char";
break;
case 13:
Type = "float";
break;
case 14:
Type = "double";
break;
case 15:
Type = "DWORD";
break;
case 17:
Type = "bool";
break;
case 18:
Type = "char_";
break;
case 19:
Type = "wchar_";
break;
case 20:
Type = "void*";
break;
case 22:
Type = "vec2";
break;
case 23:
Type = "vec3";
break;
case 24:
Type = "vec4";
break;
case 25:
Type = "matrix";
break;
case 26:
Type = "Vtable";
break;
case 27:
Type = "Array";
break;
case 29:
Type = "char*";
break;
case 30:
Type = "wchar_t*";
break;
case 21:
isBuffer = true;
SizeBuffer+=parseInt(GetAttribute(LineArray[i], "Size"));
break;
default:
isBuffer = true;
break;
}
Name = GetAttribute(LineArray[i], "Name");
if(!isBuffer){
if (SizeBuffer>0) {
FinalResult += "\tpad(__LINE__, " + SizeBuffer + ");\n";
OffsetBuffer+=parseInt(SizeBuffer);
SizeBuffer = 0;
}
if(Type == "char_"){
FinalResult += "\tchar " + Name + "[" + GetAttribute(LineArray[i], "Size") + "];";
}else if(Type == "wchar_"){
FinalResult += "\twchar_t " + Name + "[" + (GetAttribute(LineArray[i], "Size")/2) + "];";
}else if(Type == "Array"){
FinalResult += "\t" + GetAttribute(LineArray[i+1], "Name") + " " + Name + "[" + GetAttribute(LineArray[i], "Total") + "];";
}else{
FinalResult += "\t" + Type + " " + Name + ";";
}
FinalResult+= "\t//0x" + OffsetBuffer.toString(16).toUpperCase() + "\n";
OffsetBuffer+=parseInt(GetAttribute(LineArray[i], "Size"));
}else{
continue;
}
}else if(LineArray[i].indexOf("<Class Name=\"")!=-1){
OffsetBuffer = 0;
var Name = "";
//----------------------------------------------------------Class Start\
Name = GetAttribute(LineArray[i], "Name");
FinalResult += "struct " + Name + "{\n";
//----------------------------------------------------------Class Start
}else if(LineArray[i].indexOf("</Class>")!=-1){
if (SizeBuffer>0) {
FinalResult += "\tpad(__LINE__, " + SizeBuffer + ");\n";
SizeBuffer = 0;
}
FinalResult += "};\n\n";
}
//------------------------------------------------------------LOOPTHROUGHLINES
}
document.getElementById("output").value = FinalResult;
}
function startit(){
document.getElementById("ConvertButton").addEventListener("click", doWork);
}
</script>
</head>
<body>
Reclass XML Files To c++ Structs Parser By <font color="blue">TrisT</font>.<br><br>
the pad function is the following macro(credits to <font color="purple">./Zzzz</font> aka <font color="purple">mambda</font>):<br>
<div>
<code>
<font color="purple">
#define padInternal(i, a) private: char PaddingVariable## a[i]; public:<br>
#define pad(i, a) padInternal(a, i)<br>
</font>
</code>
</div>
<br>
protip: make it so the structs aren't padded by the compiler by doing:<br>
<div>
<code>
<font color="purple">
#pragma pack(push, 1) //where padding goes away<br>
</font>
<font color="blue">
struct MyStruct{<br>
&nbsp;&nbsp;&nbsp;&nbsp;byte example;<br>
&nbsp;&nbsp;&nbsp;&nbsp;int NowAtOffset0x1;<br>
&nbsp;&nbsp;&nbsp;&nbsp;int NowAtOffset0x5;<br>
};
</font><br>
<font color="purple">
#pragma(pop) //where padding comes back
</font>
<br>
<br>
</code>
</div>
Put Reclass XML Here:<br>
<textarea id="ReclassXML" rows="20" cols="150"></textarea>
<button id="ConvertButton">Convert</button>
<hr>
<textarea id="output" rows="20" cols="150"></textarea>
<script type="text/javascript">startit();</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment