private static JSONArray Cache_Git_Repo(string repo_url)
        {
            //EXAMPLE:  https://api.github.com/repos/dsisco11/SR_Plugin_Loader/git/trees/master?recursive=1
            string url     = String.Format("{0}/git/trees/master?recursive=1", repo_url.TrimEnd(new char[] { '\\', '/' }));
            string jsonStr = null;

            if (!remote_file_cache.ContainsKey(url))
            {
                // Fetch repo information
                //jsonStr = webClient.DownloadString(url);
                jsonStr = GetString(url);
                if (jsonStr == null || jsonStr.Length <= 0)
                {
                    return(null);
                }

                remote_file_cache.Add(url, ENCODING.GetBytes(jsonStr));
                SLog.Debug("Cached repository: {0}", url);
            }
            else
            {
                jsonStr = ENCODING.GetString(remote_file_cache[url]);
            }

            // Parse the json response from GitHub
            var git  = SimpleJSON.JSON.Parse(jsonStr);
            var tree = git["tree"].AsArray;

            return(tree);
        }
Beispiel #2
0
                /// <summary>
                /// Converts the part into the byte array to be spent to the service.
                /// </summary>
                public byte[] toByteArray()
                {
                    /* Construct the header. */
                    StringBuilder header = new StringBuilder();

                    header.Append("Content-Disposition: form-data; name=\"" + field + '\"');
                    if (filename != null)
                    {
                        header.Append("; filename=\"" + filename + '\"');
                    }
                    header.Append("\r\n");

                    if (type != null)
                    {
                        header.Append("Content-Type: " + type + "\r\n");
                    }

                    header.Append("\r\n");

                    /* Assemble the whole part. */
                    MemoryStream buf = new MemoryStream();

                    byte[] headerBytes = ENCODING.GetBytes(header.ToString());
                    buf.Write(headerBytes, 0, headerBytes.Length);
                    buf.Write(content, 0, content.Length);

                    return(buf.ToArray());
                }
        public static string Get_Repo_SHA(string repo_url)
        {
            //EXAMPLE:  https://api.github.com/repos/dsisco11/SR_Plugin_Loader/git/trees/master?recursive=1
            string url = String.Format("{0}/git/trees/master?recursive=1", repo_url.TrimEnd(new char[] { '\\', '/' }));

            if (!remote_file_cache.ContainsKey(url))
            {
                Cache_Git_Repo(repo_url);
            }

            string jsonStr = ENCODING.GetString(remote_file_cache[url]);
            // Parse the cached json response from GitHub
            var git = SimpleJSON.JSON.Parse(jsonStr);

            return(git["sha"].Value);
        }
Beispiel #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IntegerArray"/> struct.
        /// </summary>
        /// <param name="source">The array range to wrap.</param>
        /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
        /// <param name="itemsCount">The number of <see cref="UInt32"/> items in <paramref name="source"/>.</param>
        /// <param name="encoding">Byte encoding.</param>
        public IntegerArray(BYTES source, int byteOffset, int itemsCount, ENCODING encoding)
        {
            _Data        = source.Slice(byteOffset);
            _ByteStride  = encoding.ByteLength();
            this._Setter = null;
            this._Getter = null;

            if (itemsCount < this.Count)
            {
                _Data = _Data.Slice(0, itemsCount * _ByteStride);
            }

            switch (encoding)
            {
            case ENCODING.UNSIGNED_BYTE:
            {
                this._Setter = this._SetValueU8;
                this._Getter = this._GetValueU8;
                break;
            }

            case ENCODING.UNSIGNED_SHORT:
            {
                this._Setter = this._SetValueU16;
                this._Getter = this._GetValueU16;
                break;
            }

            case ENCODING.UNSIGNED_INT:
            {
                this._Setter = this._SetValue <UInt32>;
                this._Getter = this._GetValue <UInt32>;
                break;
            }

            default: throw new ArgumentException(nameof(encoding));
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="repo_url"></param>
        /// <returns>JSONArray holding all of the repository master branch entries</returns>
        private static IEnumerator Cache_Git_Repo_Async(string repo_url)
        {
            //EXAMPLE:  https://api.github.com/repos/dsisco11/SR_Plugin_Loader/git/trees/master?recursive=1
            string ghurl = Extract_Repository_URL_From_Github_URL(repo_url.TrimEnd(new char[] { '\\', '/' }));
            string url   = String.Format("{0}/git/trees/master?recursive=1", ghurl);

            byte[] buf     = null;
            string jsonStr = null;

            if (!remote_file_cache.ContainsKey(url))
            {
                // Fetch repo information
                //jsonStr = webClient.DownloadString(url);
                IEnumerator iter = GetAsync(url);
                while (iter.MoveNext())
                {
                    yield return(null);
                }

                if (iter.Current == null)
                {
                    yield return(null);

                    yield break;
                }

                buf = iter.Current as byte[];
                if (buf == null || buf.Length <= 0)
                {
                    yield return(null);

                    yield break;
                }

                jsonStr = ENCODING.GetString(buf);
                if (jsonStr == null || jsonStr.Length <= 0)
                {
                    yield return(null);

                    yield break;
                }

                //Check again just to make sure, because async methods could screw us up here.
                if (!remote_file_cache.ContainsKey(url))
                {
                    remote_file_cache.Add(url, ENCODING.GetBytes(jsonStr));
                }
                remote_file_cache[url] = ENCODING.GetBytes(jsonStr);

                SLog.Debug("Cached repository: {0}", repo_url);
            }
            else
            {
                jsonStr = ENCODING.GetString(remote_file_cache[url]);
                //PLog.Info("CACHE: {0}", jsonStr);
                //DebugHud.Log(remote_file_cache.ToLogString());
            }

            // Parse the json response from GitHub
            var git  = SimpleJSON.JSON.Parse(jsonStr);
            var tree = git["tree"].AsArray;

            yield return(tree);

            yield break;
        }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IntegerArray"/> struct.
 /// </summary>
 /// <param name="source">The array range to wrap.</param>
 /// <param name="encoding">Byte encoding.</param>
 public IntegerArray(BYTES source, ENCODING encoding = ENCODING.UNSIGNED_INT)
     : this(source, 0, int.MaxValue, encoding)
 {
 }
Beispiel #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="IntegerArray"/> struct.
 /// </summary>
 /// <param name="source">The array to wrap.</param>
 /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
 /// <param name="itemsCount">The number of <see cref="UInt32"/> items in <paramref name="source"/>.</param>
 /// <param name="encoding">Byte encoding.</param>
 public IntegerArray(Byte[] source, int byteOffset, int itemsCount, ENCODING encoding)
     : this(new BYTES(source), byteOffset, itemsCount, encoding)
 {
 }
Beispiel #8
0
        private bool ApplychkAll(BinaryReader br)
        {
            cHKTokens = new List <CHKToken>();

            br.BaseStream.Position = 0;

            while (br.BaseStream.Position < br.BaseStream.Length)
            {
                if (!Applychk(br))
                {
                    return(false);
                }
            }


            if (TILE == null)
            {
                TILE = (ushort[])MTXM.Clone();
            }


            if (BYTESTRx == null)
            {
                BYTESTRx = BYTESTR;
            }

            if (LOADSTRx == null)
            {
                LOADSTRx = (string[])LOADSTR.Clone();
            }

            if (IOWN == null)
            {
                //IOWN = (byte[])OWNR.Clone();
                throw new Exception("");
            }

            //만약 인코딩이 없을 경우
            if (ENCODING == null)
            {
                ENCODING = System.Text.Encoding.UTF8;

                EncodingSelectDialog encodingSelectDialog = new EncodingSelectDialog(this);
                encodingSelectDialog.ShowDialog();
            }

            for (int i = 0; i < BYTESTRx.Count; i++)
            {
                //여기서 작업해준다.
                string s = ENCODING.GetString(BYTESTRx[i]);

                LOADSTRx[i] = UseMapEditor.Tools.StringTool.ReadRawString(s);
            }

            for (int i = 0; i < DD2.Count; i++)
            {
                DoodadPallet pallete = UseMapEditor.Global.WindowTool.MapViewer.tileSet.DoodadPallets[TILETYPE][DD2[i].ID];;

                if (THG2.Exists(x => (x.X == DD2[i].X) & (x.Y == DD2[i].Y)))
                {
                    CTHG2 s = THG2.Find(x => (x.X == DD2[i].X) & (x.Y == DD2[i].Y));

                    if (s.ID == pallete.dddOverlayID)
                    {
                        THG2.Remove(s);
                    }
                }
            }



            TriggerLoad();



            //soundDatas
            uint hmpq = OpenArchive();

            soundDatas.Clear();
            for (int i = 0; i < WAV.Length; i++)
            {
                string d = WAV[i].String;
                if (WAV[i].IsLoaded)
                {
                    SoundData soundData = new SoundData();
                    soundData.path  = d;
                    soundData.bytes = ReadMPQFileC(hmpq, d);
                    if (soundData.bytes.Length != 0)
                    {
                        soundDatas.Add(soundData);
                    }
                }
            }
            CloseArchive(hmpq);



            return(true);
        }
Beispiel #9
0
        private void GetCHK(BinaryWriter bw, CHKToken cHKToken, TOKENTYPE tOKENTYPE)
        {
            byte[] tokenbyte;

            if (tOKENTYPE == TOKENTYPE.NULL)
            {
                tokenbyte = System.Text.Encoding.ASCII.GetBytes(cHKToken.code.PadRight(4, ' '));
            }
            else
            {
                tokenbyte = System.Text.Encoding.ASCII.GetBytes(tOKENTYPE.ToString().PadRight(4, ' '));
            }


            //에디터로부터 CHK데이터를 가져오는 함수
            switch (tOKENTYPE)
            {
            case TOKENTYPE.NULL:
                bw.Write(cHKToken.bytes);

                break;

            case TOKENTYPE.ENCD:
                bw.Write(tokenbyte);
                bw.Write((int)4);
                bw.Write(ENCODING.CodePage);

                break;

            case TOKENTYPE.VER:
                bw.Write(tokenbyte);
                bw.Write((int)2);
                bw.Write(VER);

                break;

            case TOKENTYPE.TYPE:
                bw.Write(tokenbyte);
                bw.Write((int)4);
                bw.Write(TYPE);

                break;

            case TOKENTYPE.IVE2:
                bw.Write(tokenbyte);
                bw.Write((int)2);
                bw.Write(IVE2);

                break;

            case TOKENTYPE.VCOD:
                bw.Write(tokenbyte);
                bw.Write(VCOD.Length);
                bw.Write(VCOD);

                break;

            case TOKENTYPE.IOWN:
                bw.Write(tokenbyte);
                bw.Write(IOWN.Length);
                bw.Write(IOWN);

                break;

            case TOKENTYPE.OWNR:
                //TODO:스타트로케이션 확인 후 IOWN수정해야됨.
                OWNR = (byte[])IOWN.Clone();

                bool[] pexist = new bool[8];
                for (int i = 0; i < UNIT.Count; i++)
                {
                    if (UNIT[i].unitID == 214)
                    {
                        pexist[UNIT[i].player] = true;
                    }
                }
                for (int i = 0; i < 8; i++)
                {
                    if (!pexist[i])
                    {
                        OWNR[i] = 0;
                    }
                }


                bw.Write(tokenbyte);
                bw.Write(OWNR.Length);
                bw.Write(OWNR);

                break;

            case TOKENTYPE.SIDE:
                bw.Write(tokenbyte);
                bw.Write(SIDE.Length);
                bw.Write(SIDE);

                break;

            case TOKENTYPE.COLR:
                bw.Write(tokenbyte);
                bw.Write(COLR.Length);
                bw.Write(COLR);

                break;

            case TOKENTYPE.CRGB:
                bw.Write(tokenbyte);
                bw.Write(32);
                for (int i = 0; i < 8; i++)
                {
                    bw.Write(CRGB[i].R);
                    bw.Write(CRGB[i].G);
                    bw.Write(CRGB[i].B);
                }
                bw.Write(CRGBIND);

                break;

            case TOKENTYPE.UNIT:
                bw.Write(tokenbyte);
                bw.Write(UNIT.Count * 36);
                for (int i = 0; i < UNIT.Count; i++)
                {
                    bw.Write(UNIT[i].unitclass);
                    bw.Write(UNIT[i].X);
                    bw.Write(UNIT[i].Y);
                    bw.Write(UNIT[i].unitID);
                    bw.Write(UNIT[i].linkFlag);
                    bw.Write(UNIT[i].validstatusFlag);
                    bw.Write(UNIT[i].validunitFlag);
                    bw.Write(UNIT[i].player);
                    bw.Write(UNIT[i].hitPoints);
                    bw.Write(UNIT[i].shieldPoints);
                    bw.Write(UNIT[i].energyPoints);
                    bw.Write(UNIT[i].resoruceAmount);
                    bw.Write(UNIT[i].hangar);
                    bw.Write(UNIT[i].stateFlag);
                    bw.Write(UNIT[i].unused);
                    bw.Write(UNIT[i].linkedUnit);
                }

                break;

            case TOKENTYPE.ERA:
                bw.Write(tokenbyte);
                bw.Write((int)2);
                bw.Write((ushort)TILETYPE);

                break;

            case TOKENTYPE.DIM:
                bw.Write(tokenbyte);
                bw.Write((int)4);
                bw.Write((ushort)WIDTH);
                bw.Write((ushort)HEIGHT);

                break;

            case TOKENTYPE.TILE:
                bw.Write(tokenbyte);
                bw.Write((int)WIDTH * HEIGHT * 2);
                for (int i = 0; i < WIDTH * HEIGHT; i++)
                {
                    bw.Write(TILE[i]);
                }

                break;

            case TOKENTYPE.MTXM:
                bw.Write(tokenbyte);
                bw.Write((int)WIDTH * HEIGHT * 2);
                for (int i = 0; i < WIDTH * HEIGHT; i++)
                {
                    bw.Write(MTXM[i]);
                }

                break;

            case TOKENTYPE.DD2:
                bw.Write(tokenbyte);
                bw.Write((int)DD2.Count * 8);
                for (int i = 0; i < DD2.Count; i++)
                {
                    bw.Write(DD2[i].ID);
                    bw.Write(DD2[i].X);
                    bw.Write(DD2[i].Y);
                    bw.Write(DD2[i].PLAYER);
                    bw.Write(DD2[i].FLAG);
                }

                break;

            case TOKENTYPE.THG2:
                bw.Write(tokenbyte);

                DDDTHG2.AddRange(THG2);

                bw.Write((int)DDDTHG2.Count * 10);
                for (int i = 0; i < DDDTHG2.Count; i++)
                {
                    bw.Write(DDDTHG2[i].ID);
                    bw.Write(DDDTHG2[i].X);
                    bw.Write(DDDTHG2[i].Y);
                    bw.Write(DDDTHG2[i].PLAYER);
                    bw.Write(DDDTHG2[i].UNUSED);
                    bw.Write(DDDTHG2[i].FLAG);
                }

                break;

            case TOKENTYPE.MASK:
                bw.Write(tokenbyte);
                bw.Write((int)MASK.Length);
                bw.Write(MASK);

                break;

            case TOKENTYPE.STRx:
                bw.Write(tokenbyte);

                {
                    int strptrlen = stringDatas.Count * 4 + 4;

                    MemoryStream memory = new MemoryStream();
                    BinaryWriter tbw    = new BinaryWriter(memory);

                    uint[] strptr = new uint[stringDatas.Count];
                    for (int i = 0; i < stringDatas.Count; i++)
                    {
                        byte[] bytes = ENCODING.GetBytes(stringDatas[i].CodeString);
                        strptr[i] = (uint)((uint)tbw.BaseStream.Position + strptrlen);
                        tbw.Write(bytes);
                        tbw.Write((byte)0);
                    }


                    bw.Write((uint)(tbw.BaseStream.Length + strptrlen));
                    bw.Write((uint)stringDatas.Count);
                    for (int i = 0; i < stringDatas.Count; i++)
                    {
                        bw.Write(strptr[i]);
                    }
                    bw.Write(memory.ToArray());
                    tbw.Close();
                    memory.Close();
                }



                //long strptrstart = bw.BaseStream.Position;


                //bw.Write((uint)0);


                //long ptrpos = bw.BaseStream.Position;


                //for (int i = 0; i < stringDatas.Count; i++)
                //{
                //    bw.Write((uint)0);
                //}


                //long endpos = bw.BaseStream.Position;
                //bw.BaseStream.Position = strptrstart;
                //bw.Write((uint)endpos - strptrstart);


                //for (int i = 0; i < stringDatas.Count; i++)
                //{
                //    bw.Write(strptr[i]);
                //}


                //bw.BaseStream.Position = endpos;
                break;

            case TOKENTYPE.SPRP:
                bw.Write(tokenbyte);
                bw.Write((int)4);
                bw.Write((ushort)SCEARIONAME.ResultIndex);
                bw.Write((ushort)SCEARIODES.ResultIndex);

                break;

            case TOKENTYPE.FORC:
                bw.Write(tokenbyte);
                bw.Write((int)20);
                bw.Write(FORCE);
                bw.Write((ushort)FORCENAME[0].ResultIndex);
                bw.Write((ushort)FORCENAME[1].ResultIndex);
                bw.Write((ushort)FORCENAME[2].ResultIndex);
                bw.Write((ushort)FORCENAME[3].ResultIndex);
                bw.Write(FORCEFLAG);
                break;

            case TOKENTYPE.MRGN:
                bw.Write(tokenbyte);
                bw.Write((int)5100);

                for (int i = 0; i < 255; i++)
                {
                    LocationData locationData = LocationDatas.SingleOrDefault(x => x.INDEX == (i + 1));

                    if (locationData == null)
                    {
                        bw.Write(new byte[20]);
                    }
                    else
                    {
                        bw.Write(locationData.L);
                        bw.Write(locationData.T);
                        bw.Write(locationData.R);
                        bw.Write(locationData.B);
                        bw.Write((ushort)locationData.STRING.ResultIndex);
                        bw.Write(locationData.FLAG);
                    }
                }

                break;

            case TOKENTYPE.UPRP:
                bw.Write(tokenbyte);
                bw.Write((int)UPRP.Length * 20);
                for (int i = 0; i < UPRP.Length; i++)
                {
                    bw.Write(UPRP[i].STATUSVALID);
                    bw.Write(UPRP[i].POINTVALID);
                    bw.Write(UPRP[i].PLAYER);
                    bw.Write(UPRP[i].HITPOINT);
                    bw.Write(UPRP[i].SHIELDPOINT);
                    bw.Write(UPRP[i].ENERGYPOINT);
                    bw.Write(UPRP[i].RESOURCE);
                    bw.Write(UPRP[i].HANGAR);
                    bw.Write(UPRP[i].STATUSFLAG);
                    bw.Write(UPRP[i].UNUSED);
                }
                break;

            case TOKENTYPE.UPUS:
                bw.Write(tokenbyte);
                bw.Write((int)UPUS.Length);
                bw.Write(UPUS);
                break;

            case TOKENTYPE.WAV:
                bw.Write(tokenbyte);
                bw.Write((int)WAV.Length * 4);

                for (int i = 0; i < WAV.Length; i++)
                {
                    bw.Write(WAV[i].ResultIndex);
                }
                break;

            case TOKENTYPE.SWNM:
                bw.Write(tokenbyte);
                bw.Write((int)SWNM.Length * 4);

                for (int i = 0; i < SWNM.Length; i++)
                {
                    bw.Write(SWNM[i].ResultIndex);
                }
                break;

            case TOKENTYPE.PUNI:
                bw.Write(tokenbyte);
                bw.Write((int)5700);
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PUNI.UNITENABLED[i]);
                }
                bw.Write(PUNI.DEFAULT);
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PUNI.USEDEFAULT[i]);
                }

                break;

            case TOKENTYPE.PUPx:
                bw.Write(tokenbyte);
                bw.Write((int)2318);
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PUPx.MAXLEVEL[i]);
                }
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PUPx.STARTLEVEL[i]);
                }
                bw.Write(PUPx.DEFAULTMAXLEVEL);
                bw.Write(PUPx.DEFAULTSTARTLEVEL);
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PUPx.USEDEFAULT[i]);
                }

                break;

            case TOKENTYPE.PTEx:
                bw.Write(tokenbyte);
                bw.Write((int)1672);
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PTEx.MAXLEVEL[i]);
                }
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PTEx.STARTLEVEL[i]);
                }
                bw.Write(PTEx.DEFAULTMAXLEVEL);
                bw.Write(PTEx.DEFAULTSTARTLEVEL);
                for (int i = 0; i < 12; i++)
                {
                    bw.Write(PTEx.USEDEFAULT[i]);
                }

                break;

            case TOKENTYPE.UNIx:
                bw.Write(tokenbyte);
                bw.Write((int)4168);
                for (int i = 0; i < 228; i++)
                {
                    bw.Write(UNIx.USEDEFAULT[i]);
                }

                for (int i = 0; i < 228; i++)
                {
                    bw.Write(UNIx.HIT[i]);
                }
                for (int i = 0; i < 228; i++)
                {
                    bw.Write(UNIx.SHIELD[i]);
                }
                for (int i = 0; i < 228; i++)
                {
                    bw.Write(UNIx.ARMOR[i]);
                }
                for (int i = 0; i < 228; i++)
                {
                    bw.Write(UNIx.BUILDTIME[i]);
                }
                for (int i = 0; i < 228; i++)
                {
                    bw.Write(UNIx.MIN[i]);
                }
                for (int i = 0; i < 228; i++)
                {
                    bw.Write(UNIx.GAS[i]);
                }
                for (int i = 0; i < 228; i++)
                {
                    bw.Write((ushort)UNIx.STRING[i].ResultIndex);
                }
                for (int i = 0; i < 130; i++)
                {
                    bw.Write(UNIx.DMG[i]);
                }
                for (int i = 0; i < 130; i++)
                {
                    bw.Write(UNIx.BONUSDMG[i]);
                }

                break;

            case TOKENTYPE.UPGx:
                bw.Write(tokenbyte);
                bw.Write((int)794);
                for (int i = 0; i < 61; i++)
                {
                    bw.Write(UPGx.USEDEFAULT[i]);
                }
                bw.Write((byte)0);
                for (int i = 0; i < 61; i++)
                {
                    bw.Write(UPGx.BASEMIN[i]);
                }
                for (int i = 0; i < 61; i++)
                {
                    bw.Write(UPGx.BONUSMIN[i]);
                }
                for (int i = 0; i < 61; i++)
                {
                    bw.Write(UPGx.BASEGAS[i]);
                }
                for (int i = 0; i < 61; i++)
                {
                    bw.Write(UPGx.BONUSGAS[i]);
                }
                for (int i = 0; i < 61; i++)
                {
                    bw.Write(UPGx.BASETIME[i]);
                }
                for (int i = 0; i < 61; i++)
                {
                    bw.Write(UPGx.BONUSTIME[i]);
                }

                break;

            case TOKENTYPE.TECx:
                bw.Write(tokenbyte);
                bw.Write((int)396);
                for (int i = 0; i < 44; i++)
                {
                    bw.Write(TECx.USEDEFAULT[i]);
                }
                for (int i = 0; i < 44; i++)
                {
                    bw.Write(TECx.MIN[i]);
                }
                for (int i = 0; i < 44; i++)
                {
                    bw.Write(TECx.GAS[i]);
                }
                for (int i = 0; i < 44; i++)
                {
                    bw.Write(TECx.BASETIME[i]);
                }
                for (int i = 0; i < 44; i++)
                {
                    bw.Write(TECx.ENERGY[i]);
                }

                break;

            case TOKENTYPE.TRIG:
                bw.Write(tokenbyte);
                bw.Write((int)2400 * TRIG.Count);
                for (int i = 0; i < TRIG.Count; i++)
                {
                    for (int c = 0; c < 16; c++)
                    {
                        bw.Write(TRIG[i].conditions[c].locid);
                        bw.Write(TRIG[i].conditions[c].player);
                        bw.Write(TRIG[i].conditions[c].amount);
                        bw.Write(TRIG[i].conditions[c].unitid);
                        bw.Write(TRIG[i].conditions[c].comparison);
                        bw.Write(TRIG[i].conditions[c].condtype);
                        bw.Write(TRIG[i].conditions[c].restype);
                        bw.Write(TRIG[i].conditions[c].flags);
                        bw.Write(TRIG[i].conditions[c].maskflag);
                    }
                    for (int a = 0; a < 64; a++)
                    {
                        bw.Write(TRIG[i].actions[a].locid1);
                        bw.Write(TRIG[i].actions[a].strid);
                        bw.Write(TRIG[i].actions[a].wavid);
                        bw.Write(TRIG[i].actions[a].time);
                        bw.Write(TRIG[i].actions[a].player1);
                        bw.Write(TRIG[i].actions[a].player2);
                        bw.Write(TRIG[i].actions[a].unitid);
                        bw.Write(TRIG[i].actions[a].acttype);
                        bw.Write(TRIG[i].actions[a].amount);
                        bw.Write(TRIG[i].actions[a].flags);
                        bw.Write(TRIG[i].actions[a].padding);
                        bw.Write(TRIG[i].actions[a].maskflag);
                    }

                    bw.Write(TRIG[i].exeflag);
                    bw.Write(TRIG[i].playerlist);
                    bw.Write(TRIG[i].trigindex);
                }


                break;

            case TOKENTYPE.MBRF:
                bw.Write(tokenbyte);
                bw.Write((int)2400 * MBRF.Count);
                for (int i = 0; i < MBRF.Count; i++)
                {
                    for (int c = 0; c < 16; c++)
                    {
                        bw.Write(MBRF[i].conditions[c].locid);
                        bw.Write(MBRF[i].conditions[c].player);
                        bw.Write(MBRF[i].conditions[c].amount);
                        bw.Write(MBRF[i].conditions[c].unitid);
                        bw.Write(MBRF[i].conditions[c].comparison);
                        bw.Write(MBRF[i].conditions[c].condtype);
                        bw.Write(MBRF[i].conditions[c].restype);
                        bw.Write(MBRF[i].conditions[c].flags);
                        bw.Write(MBRF[i].conditions[c].maskflag);
                    }
                    for (int a = 0; a < 64; a++)
                    {
                        bw.Write(MBRF[i].actions[a].locid1);
                        bw.Write(MBRF[i].actions[a].strid);
                        bw.Write(MBRF[i].actions[a].wavid);
                        bw.Write(MBRF[i].actions[a].time);
                        bw.Write(MBRF[i].actions[a].player1);
                        bw.Write(MBRF[i].actions[a].player2);
                        bw.Write(MBRF[i].actions[a].unitid);
                        bw.Write(MBRF[i].actions[a].acttype);
                        bw.Write(MBRF[i].actions[a].amount);
                        bw.Write(MBRF[i].actions[a].flags);
                        bw.Write(MBRF[i].actions[a].padding);
                        bw.Write(MBRF[i].actions[a].maskflag);
                    }

                    bw.Write(MBRF[i].exeflag);
                    bw.Write(MBRF[i].playerlist);
                    bw.Write(MBRF[i].trigindex);
                }


                break;
            }
        }
Beispiel #10
0
 public MemoryAccessInfo(string name, int byteOffset, int itemsCount, int byteStride, DIMENSIONS dimensions, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
 {
     this.Name       = name;
     this.ByteOffset = byteOffset;
     this.ItemsCount = itemsCount;
     this.ByteStride = byteStride;
     this.Dimensions = dimensions;
     this.Encoding   = encoding;
     this.Normalized = normalized;
 }
        public FloatingAccessor(BYTES source, int byteOffset, int itemsCount, int byteStride, int dimensions, ENCODING encoding, Boolean normalized)
        {
            var enclen = encoding.ByteLength();

            this._Data       = source.Slice(byteOffset);
            this._Getter     = null;
            this._Setter     = null;
            this._ByteStride = Math.Max(byteStride, enclen * dimensions);
            this._EncodedLen = enclen;
            this._ItemCount  = this._Data.Count / this._ByteStride;

            // strided buffers usually have room for an extra item
            if ((_Data.Count % _ByteStride) >= enclen * dimensions)
            {
                ++_ItemCount;
            }

            _ItemCount = Math.Min(itemsCount, _ItemCount);

            if (encoding == ENCODING.FLOAT)
            {
                this._Setter = this._SetValue <Single>;
                this._Getter = this._GetValue <Single>;
                return;
            }

            if (normalized)
            {
                switch (encoding)
                {
                case ENCODING.BYTE:
                {
                    this._Setter = this._SetNormalizedS8;
                    this._Getter = this._GetNormalizedS8;
                    break;
                }

                case ENCODING.UNSIGNED_BYTE:
                {
                    this._Setter = this._SetNormalizedU8;
                    this._Getter = this._GetNormalizedU8;
                    break;
                }

                case ENCODING.SHORT:
                {
                    this._Setter = this._SetNormalizedS16;
                    this._Getter = this._GetNormalizedS16;
                    break;
                }

                case ENCODING.UNSIGNED_SHORT:
                {
                    this._Setter = this._SetNormalizedU16;
                    this._Getter = this._GetNormalizedU16;
                    break;
                }

                default: throw new ArgumentException(nameof(encoding));
                }
            }
            else
            {
                switch (encoding)
                {
                case ENCODING.BYTE:
                {
                    this._Setter = this._SetValueS8;
                    this._Getter = this._GetValueS8;
                    break;
                }

                case ENCODING.UNSIGNED_BYTE:
                {
                    this._Setter = this._SetValueU8;
                    this._Getter = this._GetValueU8;
                    break;
                }

                case ENCODING.SHORT:
                {
                    this._Setter = this._SetValueS16;
                    this._Getter = this._GetValueS16;
                    break;
                }

                case ENCODING.UNSIGNED_SHORT:
                {
                    this._Setter = this._SetValueU16;
                    this._Getter = this._GetValueU16;
                    break;
                }

                case ENCODING.UNSIGNED_INT:
                {
                    this._Setter = this._SetValueU32;
                    this._Getter = this._GetValueU32;
                    break;
                }

                case ENCODING.FLOAT:
                    break;

                default: throw new ArgumentException(nameof(encoding));
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ColorArray"/> struct.
        /// </summary>
        /// <param name="source">The array to wrap.</param>
        /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
        /// <param name="itemsCount">The number of <see cref="Vector4"/> items in <paramref name="source"/>.</param>
        /// <param name="byteStride">
        /// The byte stride between elements.
        /// If the value is zero, the size of the item is used instead.
        /// </param>
        /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param>
        /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
        /// <param name="normalized">True if values are normalized.</param>
        public ColorArray(BYTES source, int byteOffset, int itemsCount, int byteStride, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
        {
            Guard.MustBeBetweenOrEqualTo(dimensions, 3, 4, nameof(dimensions));

            _Accessor   = new FloatingAccessor(source, byteOffset, itemsCount, byteStride, dimensions, encoding, normalized);
            _Dimensions = dimensions;
        }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorArray"/> struct.
 /// </summary>
 /// <param name="source">The array to wrap.</param>
 /// <param name="byteStride">
 /// The byte stride between elements.
 /// If the value is zero, the size of the item is used instead.
 /// </param>
 /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param>
 /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
 /// <param name="normalized">True if values are normalized.</param>
 public ColorArray(BYTES source, int byteStride = 0, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
     : this(source, 0, int.MaxValue, byteStride, dimensions, encoding, normalized)
 {
 }
Beispiel #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColorArray"/> struct.
 /// </summary>
 /// <param name="source">The array to wrap.</param>
 /// <param name="byteOffset">The zero-based index of the first <see cref="Byte"/> in <paramref name="source"/>.</param>
 /// <param name="itemsCount">The number of <see cref="Vector4"/> items in <paramref name="source"/>.</param>
 /// <param name="byteStride">
 /// The byte stride between elements.
 /// If the value is zero, the size of the item is used instead.
 /// </param>
 /// <param name="dimensions">The number of elements per item. Currently only values 3 and 4 are supported.</param>
 /// <param name="encoding">A value of <see cref="ENCODING"/>.</param>
 /// <param name="normalized">True if values are normalized.</param>
 public ColorArray(Byte[] source, int byteOffset, int itemsCount, int byteStride, int dimensions = 4, ENCODING encoding = ENCODING.FLOAT, Boolean normalized = false)
     : this(new BYTES(source), byteOffset, itemsCount, byteStride, dimensions, encoding, normalized)
 {
 }