All pastes #991482 Raw Edit

Mine

public text v1 · immutable
#991482 ·published 2008-04-21 01:33 UTC
rendered paste body
public bool ProtectMap()
        {
            if (!this.open())
            {
                return false;
            }
            BinaryReader reader = new BinaryReader(this.m.MapStream);
            this.m.MapStream.Position = this.m.MapStream.Length - 4L;
            if (Functions.UIntToString(reader.ReadUInt32()) == "HEKP")
            {
                MessageBox.Show("Map is already protected.");
                if (this.closeMap)
                {
                    this.m.CloseMap();
                }
                return false;
            }
            uint pathOffset = this.m.Tags[0].PathOffset;
            BinaryWriter writer = new BinaryWriter(this.m.MapStream);
            if (this.StoreEncryptedData)
            {
                int count = ((int) (this.m.Tags[0].MetaDataOffset - pathOffset)) - 2;
                byte[] buffer = new byte[count];
                this.m.MapStream.Position = pathOffset;
                this.m.MapStream.Read(buffer, 0, count);
                RC2CryptoServiceProvider provider = new RC2CryptoServiceProvider();
                byte[] k = this.k;
                byte[] rgbIV = this.k;
                ICryptoTransform transform = provider.CreateEncryptor(k, rgbIV);
                MemoryStream stream = new MemoryStream();
                CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
                byte[] destinationArray = new byte[(4 * this.m.Tags.Length) + buffer.Length];
                byte[] buffer6 = new byte[4];
                int destinationIndex = 4 * this.m.Tags.Length;
                for (int j = 0; j < this.m.Tags.Length; j++)
                {
                    Array.Copy(Functions.RawSerialize(this.m.Tags[j].Raw.stringoffset), 0, destinationArray, j * 4, 4);
                }
                Array.Copy(buffer, 0, destinationArray, destinationIndex, buffer.Length);
                stream2.Write(destinationArray, 0, destinationArray.Length);
                stream2.FlushFinalBlock();
                byte[] buffer2 = stream.ToArray();
                this.m.MapStream.Position = this.m.MapStream.Length;
                writer.Write(buffer2);
                writer.Write(buffer2.Length);
            }
            ArrayList list = new ArrayList();
            list.AddRange(new uint[] { Functions.StringToUInt("DeLa"), Functions.StringToUInt("devc"), Functions.StringToUInt("hudg"), Functions.StringToUInt("matg"), Functions.StringToUInt("Soul"), Functions.StringToUInt("tagc"), Functions.StringToUInt("ustr") });
            ArrayList list2 = new ArrayList();
            for (int i = 0; i < this.UnprotectList.Length; i++)
            {
                if (this.UnprotectList[i].StartsWith("Tag Class"))
                {
                    list.Add(Functions.StringToUInt(this.UnprotectList[i].Substring(10)));
                }
                else
                {
                    list2.Add(Convert.ToUInt32(this.UnprotectList[i].Substring(this.UnprotectList[i].IndexOf('|') + 1)));
                }
            }
            ArrayList list3 = new ArrayList();
            list3.AddRange(new string[] { @"ui\shell\bitmaps\", @"ui\shell\bitmaps\", @"ui\shell\error\", @"ui\shell\main_menu\", @"ui\shell\multiplayer_game\", @"ui\shell\solo_game\", @"ui\shell\strings\", @"sound\sfx\ui\", @"sound\music\title1\" });
            uint stringoffset = 0;
            ArrayList list4 = new ArrayList();
            foreach (Map.Tag tag in this.m.Tags)
            {
                if ((!list.Contains(tag.TagClass) && !list2.Contains(tag.Raw.id)) && (tag.Raw.rawdatainmap != 1))
                {
                    bool flag = false;
                    for (int m = 0; m < list3.Count; m++)
                    {
                        if (tag.Path.ToLower().StartsWith(((string) list3[m]).ToLower()))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        this.m.MapStream.Position = tag.PathOffset;
                        writer.Write(new byte[tag.Path.Length]);
                        this.m.MapStream.Position = tag.PathOffset;
                        if (tag.Path.Length < "<protected>\0".Length)
                        {
                            writer.Write((byte) 0);
                            if (stringoffset == 0)
                            {
                                list4.Add(tag.Offset);
                            }
                        }
                        else if (stringoffset == 0)
                        {
                            stringoffset = tag.Raw.stringoffset;
                            writer.Write(Encoding.ASCII.GetBytes("<protected>\0"));
                        }
                        else
                        {
                            writer.Write((byte) 0);
                        }
                        this.m.MapStream.Position = tag.Offset + 0x10;
                        writer.Write(stringoffset);
                        if (tag.Raw.id == this.m.Tags[0].Raw.id)
                        {
                            this.m.MapStream.Position = tag.Offset;
                        }
                    }
                }
            }
            if (list4.Count > 0)
            {
                foreach (uint num9 in list4)
                {
                    this.m.MapStream.Position = num9 + 0x10;
                    writer.Write(stringoffset);
                }
            }
            this.m.MapStream.Position = this.m.MapStream.Length;
            writer.Write(this.StoreEncryptedData ? 1 : 0);
            writer.Write(Functions.StringToUInt("HEKP"));
            if (this.closeMap)
            {
                this.m.CloseMap();
            }
            return true;
        }