public void PrintClass(string fileName, Package.Class c) { var text = new CorrmStringBuilder($"// {c.FullName}{Utils.NLine}// "); if (c.InheritedSize > 0) { text += $"0x{c.Size - c.InheritedSize:X4} (0x{(long)c.Size:X4} - 0x{(long)c.InheritedSize:X4}){Utils.NLine}"; } else { text += $"0x{(long)c.Size:X4}{Utils.NLine}"; } text += $"{c.NameCppFull}{Utils.NLine}{{{Utils.NLine}public:{Utils.NLine}"; // Member foreach (var m in c.Members) { text += $"\t{(m.IsStatic ? "static " + m.Type : m.Type),-50} {m.Name,-58}; // 0x{(long)m.Offset:X4}(0x{(long)m.Size:X4})" + (!string.IsNullOrEmpty(m.Comment) ? " " + m.Comment : "") + (!string.IsNullOrEmpty(m.FlagsString) ? " (" + m.FlagsString + ")" : "") + $"{Utils.NLine}"; } text += $"{Utils.NLine}"; // Predefined Methods if (c.PredefinedMethods.Count > 0) { text += $"{Utils.NLine}"; foreach (var m in c.PredefinedMethods) { if (m.MethodType == PredefinedMethod.Type.Inline) { text += m.Body; } else { text += $"\t{m.Signature};"; } text += $"{Utils.NLine}{Utils.NLine}"; } } // Methods if (c.PredefinedMethods.Count > 0) { text += $"{Utils.NLine}"; foreach (var m in c.Methods) { text += $"\t{BuildMethodSignature(m, new Package.Class(), true)};{Utils.NLine}"; } } text += $"}};{Utils.NLine}{Utils.NLine}"; IncludeFile <CppLang> .AppendToSdk(Generator.SdkPath, fileName, text); }
public string BuildMethodSignature(Package.Method m, Package.Class c, bool inHeader) { var text = new CorrmStringBuilder(); // static if (m.IsStatic && inHeader && Generator.ShouldConvertStaticMethods) { text += $"static "; } // Return Type var retn = m.Parameters.Where(item => item.ParamType == Package.Method.Parameter.Type.Return).ToList(); text += (retn.Any() ? retn.First().CppType : $"void") + $" "; // inHeader if (!inHeader) { text += $"{c.NameCpp}::"; } if (m.IsStatic && Generator.ShouldConvertStaticMethods) { text += $"STATIC_"; } text += m.Name; // Parameters text += $"("; if (m.Parameters.Count > 0) { var paramList = m.Parameters .Where(p => p.ParamType != Package.Method.Parameter.Type.Return) .OrderBy(p => p.ParamType) .Select(p => (p.PassByReference ? $"const " : "") + p.CppType + (p.PassByReference ? $"& " : p.ParamType == Package.Method.Parameter.Type.Out ? $"* " : $" ") + p.Name).ToList(); if (paramList.Count > 0) { text += paramList.Aggregate((cur, next) => cur + ", " + next); } } text += $")"; return(text); }
public string BuildMethodBody(Package.Class c, Package.Method m) { var text = new CorrmStringBuilder(); // Function Pointer text += $"{{{Utils.NLine}\tstatic auto fn"; if (Generator.ShouldUseStrings) { text += $" = UObject::FindObject<UFunction>("; if (Generator.ShouldXorStrings) { text += $"_xor_(\"{m.FullName}\")"; } else { text += $"\"{m.FullName}\""; } text += $");{Utils.NLine}{Utils.NLine}"; } else { text += $" = UObject::GetObjectCasted<UFunction>({m.Index});{Utils.NLine}{Utils.NLine}"; } // Parameters if (Generator.ShouldGenerateFunctionParametersFile()) { text += $"\t{c.NameCpp}_{m.Name}_Params params;{Utils.NLine}"; } else { text += $"\tstruct{Utils.NLine}\t{{{Utils.NLine}"; foreach (var param in m.Parameters) { text += $"\t\t{param.CppType,-30} {param.Name};{Utils.NLine}"; } text += $"\t}} params;{Utils.NLine}"; } var retn = m.Parameters.Where(item => item.ParamType == Package.Method.Parameter.Type.Default).ToList(); if (retn.Any()) { foreach (var param in retn) { text += $"\tparams.{param.Name} = {param.Name};{Utils.NLine}"; } } text += $"{Utils.NLine}"; //Function Call text += $"\tauto flags = fn->FunctionFlags;{Utils.NLine}"; if (m.IsNative) { text += $"\tfn->FunctionFlags |= 0x{UEFunctionFlags.Native:X};{Utils.NLine}"; } text += $"{Utils.NLine}"; if (m.IsStatic && !Generator.ShouldConvertStaticMethods) { text += $"\tstatic auto defaultObj = StaticClass()->CreateDefaultObject();{Utils.NLine}"; text += $"\tdefaultObj->ProcessEvent(fn, ¶ms);{Utils.NLine}{Utils.NLine}"; } else { text += $"\tUObject::ProcessEvent(fn, ¶ms);{Utils.NLine}{Utils.NLine}"; } text += $"\tfn->FunctionFlags = flags;{Utils.NLine}"; //Out Parameters var rOut = m.Parameters.Where(item => item.ParamType == Package.Method.Parameter.Type.Out).ToList(); if (rOut.Any()) { text += $"{Utils.NLine}"; foreach (var param in rOut) { text += $"\tif ({param.Name} != nullptr){Utils.NLine}" + $"\t\t*{param.Name} = params.{param.Name};{Utils.NLine}"; } } text += $"{Utils.NLine}"; //Return Value var ret = m.Parameters.Where(item => item.ParamType == Package.Method.Parameter.Type.Return).ToList(); if (ret.Any()) { text += $"{Utils.NLine}\treturn params.{ret.First().Name};{Utils.NLine}"; } text += $"}}{Utils.NLine}"; return(text); }