Exemplo n.º 1
0
 public static void Init()
 {
     try {
         if (Log != null)
         {
             return;
         }
         Setup();
         ModScanner.BuildModList();
         ModPhases.RunPhase("SplashMod");
         if (!GamePatcher.PatchPhases())
         {
             Log.Log(SourceLevels.Critical, "Cannot patch game with Harmony. Non-SplashMods may not be loaded.");
         }
     } catch (Exception ex) {
         if (Log == null)
         {
             Console.WriteLine(ex);
         }
         else
         {
             Log.Error(ex);
         }
     }
 }
Exemplo n.º 2
0
 public static void Init()
 {
     try {
         if (Log == null) // First run
         {
             Setup();
             ModScanner.BuildModList();
             ModPhases.LoadMods("SplashMod");
             PatchMenuCrt();
             if (Patcher == null)
             {
                 Log.Log(SourceLevels.Critical, "Cannot patch game with Harmony. Non-SplashMods will not be loaded.");
             }
         }
     } catch (Exception ex) {
         if (Log == null)
         {
             Console.WriteLine(ex);
         }
         else
         {
             Log.Error(ex);
         }
     }
 }
Exemplo n.º 3
0
 public static object RunActionHandler(ModEntry mod, DllMeta dll, ActionDef act)
 {
     try {
         var lib = ModPhases.LoadDll(mod, dll.Path);
         if (lib == null)
         {
             return(false);
         }
         var handler = ActionMods[dll];
         foreach (var type in dll.Methods[ACTION_METHOD])
         {
             var result = ModPhases.CallInit(mod, lib, type, ACTION_METHOD, (e) => ParamValue(act, e, mod, handler));
             if (result is bool success)
             {
                 if (success)
                 {
                     return(true);
                 }
             }
             else if (result is Exception ex)
             {
                 return(ex);
             }
             else if (result != null)
             {
                 handler.Log().Info("Unexpected ActionMod result: {0}", result.GetType());
             }
         }
         return(null);
     } catch (Exception ex) { mod.Error(ex); return(null); }
 }
Exemplo n.º 4
0
 private static void AfterHideTip()
 {
     if (!FireGeoscapeOnShow)
     {
         return;
     }
     ModPhases.RunPhase("GameOnShow");
     ModPhases.RunPhase("GeoscapeOnShow");
     FireGeoscapeOnShow = false;
 }
Exemplo n.º 5
0
 private static object ParamValue(ActionDef act, ParameterInfo arg, ModEntry actionMod, ModEntry handler)
 {
     if (arg.ParameterType == typeof(ActionDef))
     {
         return(act);
     }
     if (arg.ParameterType == typeof(string))
     {
         return(actionMod.Metadata.Id);
     }
     return(ModPhases.ParamValue(arg, handler));
 }
Exemplo n.º 6
0
 // Mainly call GeoscapeOnHide and GameOnHide when quiting from Geoscape, which seems to not trigger OnLevelStateChanged.
 // May also be called if an exception bubbles to the main game loop.
 private static void BeforeQuit()
 {
     Log.Info("Game Quit");
     if (ModPhases.LastPhase?.EndsWith("OnShow", StringComparison.Ordinal) != true)
     {
         return;
     }
     ModPhases.RunPhase(ModPhases.LastPhase.Replace("OnShow", "OnHide"));
     if (ModPhases.LastPhase != "HomeOnHide")
     {
         ModPhases.RunPhase("GameOnHide");
     }
     Log.Flush();
 }
Exemplo n.º 7
0
        private static void StateChanged(string level, int prevState, int newState)
        {
            //Log.Trace( "{0} StateChanged {1} => {2}", level, prevState, newState );
            switch (prevState)
            {
            case -1:  // Uninitialized => NotLoaded
                if (level != "Home")
                {
                    ModPhases.RunPhase("GameMod");
                }
                ModPhases.RunPhase(level + "Mod");
                return;

            case 5:  // Playing => Loaded
                if (ModPhases.LastPhase?.EndsWith("OnHide", StringComparison.Ordinal) == true)
                {
                    return;
                }
                ModPhases.RunPhase(level + "OnHide");
                if (level != "Home")
                {
                    ModPhases.RunPhase("GameOnHide");
                }
                return;

            case 2:  // Loaded => Playing, OR Loaded => Unloading
                if (newState != 5)
                {
                    return;
                }
                if (level == "Geoscape")
                {
                    FireGeoscapeOnShow = true;
                }
                else
                {
                    if (level != "Home")
                    {
                        ModPhases.RunPhase("GameOnShow");
                    }
                    ModPhases.RunPhase(level + "OnShow");
                }
                return;
            }
        }
Exemplo n.º 8
0
        private static object RunActionHandler(ModEntry mod, DllMeta dll, ActionDef act)
        {
            try {
                var lib = ModPhases.LoadDll(mod, dll.Path);
                if (lib == null)
                {
                    return(false);
                }
                var handler = ActionMods[dll];
                object GetParamValue(ParameterInfo pi) => ParamValue(act, pi, mod, handler);

                object result;
                foreach (var type in dll.Methods["ActionMod"])
                {
                    result = ModPhases.CallInit(mod, lib, type, "ActionMod", GetParamValue);
                    if (result is bool success)
                    {
                        if (success)
                        {
                            return(true);
                        }
                    }
                    else if (result is Exception ex)
                    {
                        LogActionError(handler.Log(), act, ex);
                        if (InList(act.GetText("onerror"), "continue"))
                        {
                            continue;
                        }
                        if (InList(act.GetText("onerror"), "skip"))
                        {
                            return(null);
                        }
                        mod.Log().Info("Aborting Actions. Set OnError to \"Log,Continue\" or \"Log,Skip\" to ignore the error.");
                        return(ex);
                    }
                    else if (result != null)
                    {
                        handler.Log().Error("Unexpected ActionMod result: {0}", result.GetType());
                    }
                }
                return(null);
            } catch (Exception ex) { mod.Error(ex); return(null); }
        }
Exemplo n.º 9
0
 private static void MainPhase()
 {
     ModPhases.LoadMods("Init");       // PPML v0.1
     ModPhases.LoadMods("Initialize"); // PPML v0.2
     ModPhases.LoadMods("MainMod");    // Modnix
 }
Exemplo n.º 10
0
 private static void MainPhase()
 {
     ModPhases.RunPhase("Init");       // PPML v0.1
     ModPhases.RunPhase("Initialize"); // PPML v0.2
     ModPhases.RunPhase("MainMod");    // Modnix 1 & 2
 }