示例#1
0
    public override ModRegistrationData Register()
    {
        XMLConfigPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

        Debug.Log("Mk2Excavator AssemblyPath: " + XMLConfigPath);

        //XMLConfigPath = ModManager.GetModPath();
        //string text = Path.Combine(XMLConfigPath, XMLModID + Path.DirectorySeparatorChar + XMLModVersion);

        string configfile = Path.Combine(XMLConfigPath, XMLConfigFile);

        //text += String.Concat(Path.DirectorySeparatorChar + XMLConfigFile);

        Debug.Log("Mk2Excavator: Checking if XMLConfig File Exists at " + configfile);

        if (File.Exists(configfile))
        {
            mXMLFileExists = true;
            Debug.Log("Mk2Excavator: XMLConfig File Exists, loading.");
            string xmltext = File.ReadAllText(configfile);
            try
            {
                mConfig = (Mk2ExcavatorConfig)XMLParser.DeserializeObject(xmltext, typeof(Mk2ExcavatorConfig));
                // catch insane values, clamp them to lesser insane values
                if (mConfig.DigHeight < 4)
                {
                    mConfig.DigHeight = 4;
                }
                if (mConfig.DigRadius < 1)
                {
                    mConfig.DigRadius = 1;
                }
                if (mConfig.PowerPerBlockDefault < 1)
                {
                    mConfig.PowerPerBlockDefault = 1;
                }
                if (mConfig.PowerPerBlockOre < 1)
                {
                    mConfig.PowerPerBlockOre = 1;
                }
                if (mConfig.DigHeight > 2048)
                {
                    mConfig.DigHeight = 2048;
                }
                if (mConfig.DigRadius > 1024)
                {
                    mConfig.DigRadius = 1024;
                }
                if (mConfig.PowerPerBlockDefault > 10000)
                {
                    mConfig.PowerPerBlockDefault = 10000;
                }
                if (mConfig.PowerPerBlockOre > 40000)
                {
                    mConfig.PowerPerBlockOre = 40000;
                }
                if (mConfig.MaxPower > 100000)
                {
                    mConfig.MaxPower = 100000;
                }
                if (mConfig.OPBlock > 20)
                {
                    mConfig.OPBlock = 20;
                }
                if (mConfig.OPBlock < 2)
                {
                    mConfig.OPBlock = 1;
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Mk2Excavator: Something is wrong with ConfigXML, using defaults.\n Exception: " + e.ToString());
                mXMLFileExists = false;
            }
            Debug.Log("Mk2Excavator: XMLConfig File Loaded.");
        }
        else
        {
            Debug.LogWarning("Mk2Excavator: ERROR: XML File Does not exist at " + configfile);
            mXMLFileExists = false;
        }

        ModRegistrationData lRegData = new ModRegistrationData();

        lRegData.RegisterEntityHandler("FlexibleGames.Mk2Excavator");
        TerrainDataEntry      ltde;
        TerrainDataValueEntry ltdve;

        global::TerrainData.GetCubeByKey("FlexibleGames.Mk2Excavator", out ltde, out ltdve);
        bool flag = ltde != null;

        if (flag)
        {
            this.mExcavatorCubeType = ltde.CubeType;
        }
        UIManager.NetworkCommandFunctions.Add("FlexibleGames.Mk2ExcavatorWindow", new UIManager.HandleNetworkCommand(Mk2ExcavatorWindow.HandleNetworkCommand));

        return(lRegData);
    }
    // mod initializaion

    /// <summary>
    /// Register Mod
    /// </summary>
    /// <returns>ModRegistrationData for FlexibleGames.AdvancedQuarrys</returns>
    public override ModRegistrationData Register()
    {
        // load XML configurations
        //XMLConfigPath = ModManager.GetModPath();
        //string text = Path.Combine(XMLConfigPath, XMLModID + Path.DirectorySeparatorChar + XMLModVersion);
        //text += String.Concat(Path.DirectorySeparatorChar + XMLConfigFile);

        XMLConfigPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

        Debug.Log("AdvQuarrys: AssemblyPath: " + XMLConfigPath);

        string configfile = Path.Combine(XMLConfigPath, XMLConfigFile);

        Debug.Log("AdvQuarrys: Checking if XMLConfig File Exists at " + configfile);
        if (File.Exists(configfile))
        {
            mXMLFileExists = true;
            Debug.Log("AdvQuarrys: XMLConfig File Exists, loading.");
            string xmltext = File.ReadAllText(configfile);
            try
            {
                mConfig = (QuarryConfig)XMLParser.DeserializeObject(xmltext, typeof(QuarryConfig));
            }
            catch (Exception e)
            {
                Debug.LogError("AdvQuarrys: Something is wrong with ConfigXML, using defaults.\n Exception: " + e.ToString());
                mXMLFileExists = false;
                mConfig        = new QuarryConfig();
            }
            if (mXMLFileExists)
            {
                Debug.Log("AdvQuarrys: XMLConfig File Loaded.");
            }
        }
        else
        {
            GameManager.DoLocalChat("AdvQuarrys: ERROR: XML File Does not exist at " + configfile);
            mXMLFileExists = false;
        }
        if (mXMLFileExists)
        {
            if (!ValidateConfig())
            {
                mXMLFileExists = false;
                GameManager.DoLocalChat("AdvQuarrys: Quarry Config file is invalid.");
            }
        }
        // load Mk4 XML configurations
        //XMLConfigPath = ModManager.GetModPath();
        //text = Path.Combine(XMLConfigPath, XMLModID + Path.DirectorySeparatorChar + XMLModVersion);
        //text += String.Concat(Path.DirectorySeparatorChar + XMLMk4ConfigFile);
        configfile = Path.Combine(XMLConfigPath, XMLMk4ConfigFile);
        Debug.Log("AdvQuarrys: Checking if Mk4 XMLConfig File Exists at " + configfile);
        if (File.Exists(configfile))
        {
            mMk4XMLFileExists = true;
            Debug.Log("AdvQuarrys: XMLConfig File Exists, loading.");
            string xmltext = File.ReadAllText(configfile);
            try
            {
                mMk4Config = (Mk4QuarryConfig)XMLParser.DeserializeObject(xmltext, typeof(Mk4QuarryConfig));
            }
            catch (Exception e)
            {
                Debug.LogError("AdvQuarrys: Something is wrong with Mk4 ConfigXML, using defaults.\n Exception: " + e.ToString());
                mMk4XMLFileExists = false;
                mMk4Config        = new Mk4QuarryConfig();
            }
            if (mMk4XMLFileExists)
            {
                Debug.Log("AdvQuarry: Mk4 XMLConfig File Loaded.");
            }
        }
        else
        {
            GameManager.DoLocalChat("AdvQuarrys: ERROR: Mk4 XML File Does not exist at " + configfile);
            mMk4XMLFileExists = false;
        }
        if (mMk4XMLFileExists)
        {
            if (!ValidateMk4Config())
            {
                mMk4XMLFileExists = false;
                mMk4Config.Mine1  = "None";
                mMk4Config.Mine2  = "None";
                mMk4Config.Mine3  = "None";
                mMk4Config.Mine4  = "None";
                mMk4Config.Size   = 15;
                GameManager.DoLocalChat("AdvQuarrys: Mk4 Quarry Config file is invalid.");
            }
        }

        // Mk5 quarry config.
        configfile = Path.Combine(XMLConfigPath, XMLMk5ConfigFile);
        Debug.Log("AdvQuarrys: Checking if Mk5 XMLConfig File Exists at " + configfile);
        if (File.Exists(configfile))
        {
            mMk5XMLFileExists = true;
            Debug.Log("AdvQuarrys: Mk5 XMLConfig File Exists, loading.");
            string xmltext = File.ReadAllText(configfile);
            try
            {
                mMk5Config = (Mk5QuarryConfig)XMLParser.DeserializeObject(xmltext, typeof(Mk5QuarryConfig));
            }
            catch (Exception e)
            {
                Debug.LogError("AdvQuarrys: Something is wrong with Mk5 ConfigXML, using defaults.\n Exception: " + e.ToString());
                mMk5XMLFileExists = false;
                mMk5Config        = new Mk5QuarryConfig();
            }
            if (mMk5XMLFileExists)
            {
                Debug.Log("AdvQuarrys: Mk5 XMLConfig File Loaded.");
            }
        }
        else
        {
            GameManager.DoLocalChat("AdvQuarrys: ERROR: Mk5 XML File Does not exist at " + configfile);
            mMk5XMLFileExists = false;
        }
        if (mMk5XMLFileExists)
        {
            if (!ValidateMk5Config())
            {
                mMk5XMLFileExists = false;
                mMk5Config.Mine1  = "None";
                mMk5Config.Mine2  = "None";
                mMk5Config.Mine3  = "None";
                mMk5Config.Mine4  = "None";
                mMk5Config.Mine5  = "None";
                mMk5Config.Mine6  = "None";
                mMk5Config.Mine7  = "None";
                mMk5Config.Mine8  = "None";
                mMk5Config.Size   = 9;
                GameManager.DoLocalChat("AdvQuarrys: Mk5 Quarry Config file is invalid.");
            }
        }


        // register mod
        ModRegistrationData lmoddata = new ModRegistrationData();

        lmoddata.RegisterEntityHandler("FlexibleGames.AdvancedQuarrys");
        lmoddata.RegisterEntityHandler("FlexibleGames.Mk5Quarry");
        lmoddata.RegisterEntityHandler("FlexibleGames.Mk5QuarryBlock");
        lmoddata.RegisterEntityHandler("FlexibleGames.Mk5QuarryCenter");
        lmoddata.RegisterEntityHandler("FlexibleGames.Mk5QuarryPlacement");

        // UIManager.NetworkCommandFunctions.Add("FlexibleGames.Mk2ExcavatorWindow", new UIManager.HandleNetworkCommand(Mk2ExcavatorWindow.HandleNetworkCommand));

        UIManager.NetworkCommandFunctions.Add("FlexibleGames.FlexibleQuarryWindow", new UIManager.HandleNetworkCommand(FlexibleQuarryWindow.HandleNetworkCommand));

        TerrainDataEntry      lterraindata;
        TerrainDataValueEntry lterraindatavalue;

        global::TerrainData.GetCubeByKey("FlexibleGames.AdvancedQuarrys", out lterraindata, out lterraindatavalue);
        bool flag = lterraindata != null;

        if (flag)
        {
            this.mQuarryType = lterraindata.CubeType;
        }
        return(lmoddata);
    }