private int GetOffset(netvar_table table, string varname, bool from_child = false) { foreach (RecvProp *props in table.child_props) { if (Marshal.PtrToStringAnsi((IntPtr)props->m_pVarName) == varname) { return(table.offset + props->m_Offset); } } foreach (var child_tables in table.child_tables) { var ret = GetOffset(child_tables, varname, true); if (ret != -1) { return(table.offset + ret); } } foreach (var child_tables in table.child_tables) { if (Marshal.PtrToStringAnsi((IntPtr)child_tables.prop->m_pVarName) == varname) { return(table.offset + child_tables.offset); } } return(-1); }
private void DumpClasses(netvar_table table, string parent_table_name, string path, bool from_child = false) { if (table.child_props.Count == 0) { return; } if (!from_child) { System.IO.File.AppendAllText(path, $"public class {table.name} {"{"} static {parent_table_name}() {"{"} {"}"}" + Environment.NewLine); } foreach (RecvProp *props in table.child_props) { var prop_name = Marshal.PtrToStringAnsi((IntPtr)props->m_pVarName); System.IO.File.AppendAllText(path, $"public static Int32 {fix_varname( prop_name)} = g_NtvMngr.GetOffset(\"{parent_table_name}\", \"{prop_name}\");" + Environment.NewLine); } foreach (var child_tables in table.child_tables) { DumpClasses(child_tables, parent_table_name, path, true); var mprop_name = Marshal.PtrToStringAnsi((IntPtr)child_tables.prop->m_pVarName); System.IO.File.AppendAllText(path, $"public static Int32 {fix_varname( mprop_name)} = g_NtvMngr.GetOffset(\"{parent_table_name}\", \"{mprop_name}\");" + Environment.NewLine); } if (!from_child) { System.IO.File.AppendAllText(path, "}" + Environment.NewLine); } System.IO.File.AppendAllText(path, Environment.NewLine); string fix_varname(string str) { if (str.Contains("[")) { str = str.Replace("[", "_"); } if (str.Contains("]")) { str = str.Remove(str.IndexOf("]"), 1); } if (str.Contains(".")) { str = str.Replace(".", "_"); } if (str.Contains("\"")) { str = str.Replace("\"", ""); str = $"\\\"{str}\\\""; } return(str); } }
private netvar_table LoadTable(RecvTable *recvTable) { var table = new netvar_table(); table.child_props = new List <IntPtr>(); table.child_tables = new List <netvar_table>(); table.offset = 0; table.name = Marshal.PtrToStringAnsi((IntPtr)recvTable->m_pNetTableName); for (int i = 0; i < recvTable->m_nProps; i++) { count++; var pProp = &recvTable->m_pProps[i]; if ((IntPtr)pProp == IntPtr.Zero || char.IsDigit(Marshal.PtrToStringAnsi((IntPtr)pProp->m_pVarName)[0])) { continue; } if (Marshal.PtrToStringAnsi((IntPtr)pProp->m_pVarName) == "baseclass") { continue; } if (pProp->m_RecvType == 6 && (IntPtr)pProp->m_pDataTable != IntPtr.Zero) { table.child_tables.Add(LoadTable(pProp->m_pDataTable)); var last = table.child_tables.Last(); last.offset = pProp->m_Offset; last.prop = pProp; table.child_tables[table.child_tables.Count - 1] = last; } else { table.child_props.Add((IntPtr)pProp); } } return(table); }