示例#1
0
            public bool IsMadeInFurnace;       //indicate if the item is made inside a furnace

            public ModCraft()
            {
                this.Recipe          = new refItem("none", "vanilla");
                this.Inputs          = new refItem[] { };
                this.Outputs         = new refItem[] { };
                this.IsMadeInFurnace = false;
            }
示例#2
0
 public ModCraft(refItem sRecipe, refItem[] sInputs, refItem[] sOutputs, bool sIsMadeInFurnace)
 {
     this.Recipe          = sRecipe;
     this.Inputs          = sInputs;
     this.Outputs         = sOutputs;
     this.IsMadeInFurnace = sIsMadeInFurnace;
 }
示例#3
0
        public oMod(string filepath)
        {
            ////load the archive
            octar1Archive arch = octar1ArchiveSaver.LoadArchive(filepath);


            ////load the mod properties written in rootf\\modinfo
            ctar1File ctfModInfo = arch.GetFileFromPath("rootf\\modinfo");
            //create the memory stream to read the file
            MemoryStream wwwms = new MemoryStream(ctfModInfo.Content);

            //read the content of the file
            while (true)
            {
                byte IndicationByte = (byte)(wwwms.ReadByte());

                //if end of the file
                if (IndicationByte == 255)
                {
                    break;
                }

                //0x01 is mod name
                if (IndicationByte == 1)
                {
                    byte[] byteModName = MemVoid.ReadByteUntilByte(wwwms, 0);
                    this.ModName = System.Text.Encoding.UTF8.GetString(byteModName);
                }
            }
            //we have finished reading the mod info file
            wwwms.Dispose();



            ////load the items
            ctar1Folder FolderItem = arch.GetFolderFromPath("rootf\\Items");             //get the folder of the items

            foreach (ctar1File f in FolderItem.listSubFile)
            {
                //we create the variable to get the properties values.
                string strItemName    = "";
                string strItemModName = "";
                Bitmap img            = null;
                bool   boolIsBelt     = true;

                //create the memory stream used to read the content of the file
                MemoryStream ms = new MemoryStream(f.Content);
                //read the content
                while (true)
                {
                    /*
                     *
                     *
                     * bytes who describe what property is comming:
                     * -0x01 item name         string
                     * -0x02 mod name          string
                     * -0x03 is belt           bool
                     * -0x04 image file name   string
                     *
                     * -0xff end of the file, we must stop reading, nothing else is comming after.
                     *
                     */


                    //the first byte of each block indicate what's comming next.
                    byte IndicationByte = (byte)(ms.ReadByte());

                    //255 is the end of the file
                    if (IndicationByte == 255)
                    {
                        break;
                    }

                    //item name
                    if (IndicationByte == 1)
                    {
                        //get the data as byte[] and then convert it to a string
                        byte[] byteStr = MemVoid.ReadByteUntilByte(ms, 0);
                        strItemName = System.Text.Encoding.UTF8.GetString(byteStr);
                        //Program.wdebug(strItemName + "  :  " + strItemName.Length.ToString());
                    }

                    //mod name
                    if (IndicationByte == 2)
                    {
                        //get the data as byte[] and then convert it to a string
                        byte[] byteStr = MemVoid.ReadByteUntilByte(ms, 0);
                        strItemModName = System.Text.Encoding.UTF8.GetString(byteStr);
                    }

                    //IsBelt
                    if (IndicationByte == 3)
                    {
                        byte byteValue = (byte)(ms.ReadByte());
                        boolIsBelt = byteValue == 1;
                        //read the null byte that end the bool value
                        ms.ReadByte();
                    }

                    //image file name
                    if (IndicationByte == 4)
                    {
                        //get the data as byte[] and then convert it to a string
                        byte[] byteStr          = MemVoid.ReadByteUntilByte(ms, 0);
                        string strImageFileName = System.Text.Encoding.UTF8.GetString(byteStr);

                        //get the file of the image
                        ctar1File FileImage = arch.GetFileFromPath("rootf\\Items\\Images\\" + strImageFileName);
                        //creates a memory stream for the constructor
                        MemoryStream msimage = new MemoryStream(FileImage.Content);
                        img = new Bitmap(msimage);
                        msimage.Dispose();
                    }
                }

                //we have finished to read the content
                ms.Dispose();


                //create the ModItem
                ModItem newmi = new ModItem(strItemName, strItemModName, img);
                newmi.IsBelt = boolIsBelt;

                this.listItems.Add(newmi);
            }


            ////load the crafts
            ctar1Folder FolderCraft = arch.GetFolderFromPath("rootf\\Crafts");             //get the folder of the crafts

            foreach (ctar1File f in FolderCraft.listSubFile)
            {
                //these variables will be defined during the reading process
                refItem        riRecipe        = new refItem("", "");
                List <refItem> listInputs      = new List <refItem>();          //inputs and outputs will be added during the reading process
                List <refItem> listOutputs     = new List <refItem>();
                bool           ismadeinfurnace = false;

                //create the memory stream used to read the content
                MemoryStream ms = new MemoryStream(f.Content);

                //read the file
                while (true)
                {
                    /*
                     *
                     * the beginning byte for every type of "block" :
                     * -0x01 recipe                   string string
                     * -0x02 input                    string string
                     * -0x03 output                   string string
                     * -0x04 is made in furnace       bool
                     *
                     */

                    byte IndicationByte = (byte)(ms.ReadByte());

                    //if end of the file
                    if (IndicationByte == 255)
                    {
                        break;
                    }

                    //if recipe
                    if (IndicationByte == 1)
                    {
                        //read the recipe name
                        byte[] byteItemName = MemVoid.ReadByteUntilByte(ms, 0);                         //read until null caracter 0
                        riRecipe.ItemName = System.Text.Encoding.UTF8.GetString(byteItemName);

                        //read the recipe mod name
                        byte[] byteModName = MemVoid.ReadByteUntilByte(ms, 0);
                        riRecipe.ModName = System.Text.Encoding.UTF8.GetString(byteModName);
                    }

                    //if an input
                    if (IndicationByte == 2)
                    {
                        byte[] byteItemName = MemVoid.ReadByteUntilByte(ms, 0);
                        byte[] byteModName  = MemVoid.ReadByteUntilByte(ms, 0);

                        refItem newinput = new refItem();
                        newinput.ItemName = System.Text.Encoding.UTF8.GetString(byteItemName);
                        newinput.ModName  = System.Text.Encoding.UTF8.GetString(byteModName);

                        //add the new input to the list
                        listInputs.Add(newinput);
                    }

                    //if an output
                    if (IndicationByte == 3)
                    {
                        byte[] byteItemName = MemVoid.ReadByteUntilByte(ms, 0);
                        byte[] byteModName  = MemVoid.ReadByteUntilByte(ms, 0);

                        refItem newoutput = new refItem();
                        newoutput.ItemName = System.Text.Encoding.UTF8.GetString(byteItemName);
                        newoutput.ModName  = System.Text.Encoding.UTF8.GetString(byteModName);

                        //add the new output to the list
                        listOutputs.Add(newoutput);
                    }

                    //if is made in furnace
                    if (IndicationByte == 4)
                    {
                        byte byteValue = (byte)(ms.ReadByte());
                        ismadeinfurnace = byteValue == 1;
                        //read the null byte that end the bool
                        ms.ReadByte();
                    }
                }

                //we have finished to read the content
                ms.Dispose();


                //create the ModCraft
                ModCraft newcraft = new ModCraft(riRecipe, listInputs.ToArray(), listOutputs.ToArray(), ismadeinfurnace);
                this.listCrafts.Add(newcraft);
            }
        }