Guest User

ReusDumper

a guest
May 26th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SpaceTech.Content;
  6. using Reus.Settings.Model;
  7. using SpaceTech;
  8. using Microsoft.Xna.Framework.Content;
  9. using System.Reflection;
  10. using Reus.Settings.Model.Giants;
  11. using Game.Settings.Grammar;
  12. using Reus.Model.Flora;
  13. using Reus.Model.Animals;
  14. using Reus.Model.Mines;
  15. using Reus.Model.Aspects;
  16. using Reus.Model.Civilizations.Challenges;
  17. using Reus.Settings.Model.Ambassadors;
  18. using Reus.Model.Civilizations.Conversations;
  19. using System.Collections;
  20.  
  21. namespace ConsoleApplication1
  22. {
  23.     class Program
  24.     {
  25.         private static ContentManager mgr;
  26.         static void Main(string[] args)
  27.         {
  28.             ServiceProvider sp = new ServiceProvider();
  29.             String dir = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Reus\\";            
  30.             mgr = new ContentManager(sp, dir);
  31.            
  32.             Dump("Fo ", mgr.Load<GiantSettings>("Settings/Model/Giants/Forest"));
  33.             Dump("Oc", mgr.Load<GiantSettings>("Settings/Model/Giants/Ocean"));
  34.             Dump("Ro", mgr.Load<GiantSettings>("Settings/Model/Giants/Rock"));
  35.             Dump("Sw", mgr.Load<GiantSettings>("Settings/Model/Giants/Swamp"));
  36.              Display<Ruleset>("Settings/Controller/NameGenerator/Motivationals");
  37.              Display<Ruleset>("Settings/Controller/NameGenerator/Wars");
  38.              Display<Parameters>("Settings/Model/Parameters");
  39.              Display<FloraAssetDefinitionDatabase>("Settings/Model/Flora");
  40.              Display<AnimalDefinitionDatabase>("Settings/Model/Animals");
  41.              Display<MineDefinitionDatabase>("Settings/Model/Mines");
  42.              Display<AspectDefinitionDatabase>("Settings/Model/Aspects");
  43.            
  44.             Display<CivChallengeDefinitionDatabase>("Settings/Model/CivChallenges", DumpCivChallengeDefinitionDatabase);
  45.             Display<AmbassadorDefinitionDatabase>("Settings/Model/Ambassadors");
  46.             Display<Ruleset>("Settings/Controller/NameGenerator/CityNames");            
  47.             Display<TopicList>("Settings/Model/Topics");
  48.             Display<CivilizationParameters>("Settings/Model/Civilizations");
  49.             Display<Parameters>("Settings/Model/Parameters");
  50.             Console.WriteLine("Press any key");
  51.             Console.ReadLine();
  52.         }
  53.  
  54.         private static void Display<T>(string asset, Action<T> dumpAction = null) {
  55.             Console.WriteLine("Asset: " + asset + " of type " + typeof(T));
  56.             T value = mgr.Load<T>(asset);
  57.             if (dumpAction == null)
  58.             {
  59.                 Dump("", value);
  60.             }
  61.             else
  62.             {
  63.                 dumpAction(value);
  64.             }
  65.             Console.WriteLine();
  66.         }
  67.  
  68.         private static void DumpCivChallengeDefinitionDatabase(CivChallengeDefinitionDatabase ccdb)
  69.         {
  70.            
  71.             foreach (CivChallengeDescription cc in ccdb)
  72.             {
  73.                 Dump(cc.Name + " ", cc);
  74.                 foreach (ICivChallengeRequirement req in cc.MissionRequirements)
  75.                 {
  76.                     Dump("req ", req);
  77.                 }
  78.                 break;
  79.             }
  80.         }
  81.  
  82.         private static void Dump<T>(string prefix , T dinges, Boolean toplevel = true)
  83.         {
  84.             if (!toplevel) Console.WriteLine(prefix+dinges);
  85.             PropertyInfo[] pis = dinges.GetType().GetProperties();
  86.             foreach (var pi in pis)
  87.             {
  88.                 if (pi.GetIndexParameters().Length == 0)
  89.                 {
  90.                     object val = pi.GetValue(dinges, null);
  91.                     Console.WriteLine(prefix + "(property)" + pi.Name + " = " + val + " of type " + pi.PropertyType);
  92.                 }
  93.                 else
  94.                 {
  95.                     Console.Write(prefix + "(property)" + pi.Name + " is indexed by ");
  96.                     foreach (ParameterInfo ip in pi.GetIndexParameters())
  97.                     {
  98.                         Console.Write(ip.ParameterType + " ");
  99.                     }
  100.                     Console.WriteLine();
  101.                 }
  102.             }
  103.             FieldInfo[] fis = dinges.GetType().GetFields();
  104.             foreach (var fi in fis)
  105.             {
  106.                 object val = fi.GetValue(dinges);
  107.                 Console.WriteLine(prefix + fi.Name + " = " + val + " of type " + val.GetType());
  108.                 if (val.GetType().IsClass) {
  109.                     Dump(prefix + "    ", val, false);
  110.                 }
  111.             }
  112.         }
  113.     }
  114. }
Add Comment
Please, Sign In to add comment