Ejemplo n.º 1
0
 /// <summary>
 /// Adds the techs for every registered building to the database.
 /// </summary>
 internal static void AddAllTechs()
 {
     if (buildingTable == null)
     {
         throw new InvalidOperationException("Building table not loaded");
     }
     lock (PSharedData.GetLock(PRegistry.KEY_BUILDING_LOCK)) {
         PRegistry.LogPatchDebug("Register techs for {0:D} buildings".F(
                                     buildingTable.Count));
         foreach (var building in buildingTable)
         {
             if (building != null)
             {
                 try {
                     var trBuilding = Traverse.Create(building);
                     // Building is of type object because it is in another assembly
                     var addTech = Traverse.Create(building).Method(nameof(AddTech));
                     if (addTech.MethodExists())
                     {
                         addTech.GetValue();
                     }
                     else
                     {
                         PRegistry.LogPatchWarning("Invalid building technology!");
                     }
                 } catch (System.Reflection.TargetInvocationException e) {
                     // Log errors when registering building from another mod
                     PUtil.LogError("Unable to add building tech for " +
                                    building.GetType().Assembly?.GetNameSafe() + ":");
                     PUtil.LogException(e.GetBaseException());
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Adds the techs for every registered building to the database.
 /// </summary>
 internal static void AddAllTechs()
 {
     if (buildingTable == null)
     {
         throw new InvalidOperationException("Building table not loaded");
     }
     lock (PSharedData.GetLock(PRegistry.KEY_BUILDING_LOCK)) {
         PRegistry.LogPatchDebug("Register techs for {0:D} buildings".F(
                                     buildingTable.Count));
         foreach (var building in buildingTable)
         {
             if (building != null)
             {
                 var trBuilding = Traverse.Create(building);
                 // Building is of type object because it is in another assembly
                 var addTech = Traverse.Create(building).Method(nameof(AddTech));
                 if (addTech.MethodExists())
                 {
                     addTech.GetValue();
                 }
                 else
                 {
                     PRegistry.LogPatchWarning("Invalid building technology!");
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public override void Process(uint when, object _)
        {
            if (patches.TryGetValue(when, out PrivateRunList atTime) && atTime != null &&
                atTime.Count > 0)
            {
                string stage = RunAt.ToString(when);
#if DEBUG
                PRegistry.LogPatchDebug("Executing {0:D} handler(s) from {1} for stage {2}".F(
                                            atTime.Count, Assembly.GetExecutingAssembly().GetNameSafe() ?? "?", stage));
#endif
                foreach (var patch in atTime)
                {
                    try {
                        patch.Run(harmony);
                    } catch (TargetInvocationException e) {
                        // Use the inner exception
                        PUtil.LogError("Error running patches for stage " + stage + ":");
                        PUtil.LogException(e.GetBaseException());
                    }
                }