Well as I have complained, like a lot, the new unreal version 4.7-4.8 will force you to split all your networking codes into three separate functions. And if you have worked on Unreal for more than a year like me, you’ll have a crazy task of converting over 1000+ lines of codes.
So below is my little snippet that have made my life a lot easier. It’s a javascript that will do all the above tricks for you, both header and cpp file. (Just save it as .html and open with any browser.) Currently I have it print out the result where you can copy and paste one by one file to avoid any serious undo-able damage. It’s also customly built only to fix my codes, so heck, feel free to use it as a template to your own needs.
I hope by sharing this, it will help ease the pain for some of you.
<!DOCTYPE html>
<html>
<body>
<br>
Unreal Replacer!
<br>
<br>
<input type="file" id="FileInput" >
<br>
<br>
<br>
<p id="ResultText">Result Here</p>
<script type="text/javascript">
function DoIt(evt)
{
if (window.File && window.FileReader && window.FileList && window.Blob)
{
var f = evt.target.files[0];
if (f)
{
var nFileName = escape(f.name);
if (nFileName.substring(nFileName.length - 1) == "h")
{
ConvertHeaderFile(f);
}
else if (nFileName.substring(nFileName.length - 3) == "cpp")
{
ConvertCSFile(f);
}
else
{
document.getElementById("ResultText").innerHTML = "Not valid file extension: " + nFileName;
}
}
else
{
document.getElementById("ResultText").innerHTML = "Failed to load file";
}
}
else
{
alert('The File APIs are not fully supported in this browser.');
}
}
document.getElementById('FileInput').addEventListener('change', DoIt, false);
function ConvertHeaderFile(f)
{
var r = new FileReader();
r.onload = function(e)
{
var nText = e.target.result.replace(/</g,'<');;
var nResult = "";
var nStartIndex = nText.search("UFUNCTION\\(NetMulticast, Reliable\\)");
do
{
nResult += nText.substring(0, nStartIndex);
nText = nText.substring(nStartIndex);
var nEndIndex = nText.search("\\;");
if (nEndIndex != -1)
{
var nReplaceBlock = nText.substring(0, nEndIndex + 1);
var nValidationBlock = "<br>" + nText.substring(33, nEndIndex + 1).replace("void", "bool");
var nImplementationBlock = "<br>" + nText.substring(33, nEndIndex + 1);
nText = nText.substring(nEndIndex + 1, nText.length);
nResult += nReplaceBlock;
nResult += nValidationBlock.replace('\(', "_Validate\(");
nResult += nImplementationBlock.replace('\(', "_Implementation\(");
nStartIndex = nText.search("UFUNCTION\\(NetMulticast, Reliable\\)");
}
else nStartIndex = -1;
}
while (nStartIndex != -1);
nResult += nText;
nResult = nResult.replace(/(?:
|\r|
)/g, '<br />');
document.getElementById("ResultText").innerHTML = "" + nResult;
}
r.readAsText(f);
}
function ConvertCSFile(f)
{
var r = new FileReader();
r.onload = function(e)
{
var nText = e.target.result.replace(/</g,'<');
var nResult = "";
var nStartIndex = nText.search("void");
do
{
nResult += nText.substring(0, nStartIndex);
nText = nText.substring(nStartIndex, nText.length);
var nEndIndex = nText.search("\\{");
if (nEndIndex != -1)
{
var nReplaceBlock = nText.substring(0, nEndIndex);
if (nReplaceBlock.search("_Implementation") == -1)
{
nResult += nReplaceBlock;
}
else
{
var nValidationBlock = nReplaceBlock.replace("_Implementation", "_Validate");
nResult += nValidationBlock.replace("void", "bool") + "{return true;}" + "<br>";
nResult += nReplaceBlock;
}
nText = nText.substring(nEndIndex, nText.length);
nStartIndex = nText.search("void");
}
else nStartIndex = -1;
}
while (nStartIndex != -1);
nResult += nText;
nResult = nResult.replace(/(?:
|\r|
)/g, '<br />');
document.getElementById("ResultText").innerHTML = "" + nResult;
}
r.readAsText(f);
}
</script>
</body>
</html>