示例#1
0
        public override void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer)
        {
            var str = (String)value;

            var tokens = TokenizeString(str);

            if (tokens.Count > 1)
            {
                writer.WriteStartArray();

                foreach (var token in tokens)
                {
                    InternalWriteValue(writer, JsonToken.String);

                    writer.WriteRaw(EncodedStringUtil.GetStringForJSON(token));
                }

                writer.WriteEndArray();
            }
            else
            {
                InternalWriteValue(writer, JsonToken.String);

                writer.WriteRaw(EncodedStringUtil.GetStringForJSON(str));
            }
        }
示例#2
0
        public Byte[] Write(Encoding encoding)
        {
            Assert.IsNotNull(encoding, nameof(encoding));

            var stream = new MemoryStream();

            Interop.WriteStructToStream(stream, Header);
            Interop.WriteStructToStream(stream, Attack);

            stream.WriteByte((Byte)Arts.Count);
            foreach (var info in Arts)
            {
                Interop.WriteStructToStream(stream, info);
            }

            stream.WriteByte((Byte)Crafts.Count);
            foreach (var info in Crafts)
            {
                Interop.WriteStructToStream(stream, info);
            }

            stream.WriteByte((Byte)SCrafts.Count);
            foreach (var info in SCrafts)
            {
                Interop.WriteStructToStream(stream, info);
            }

            stream.WriteByte((Byte)SupportCrafts.Count);
            foreach (var info in SupportCrafts)
            {
                Interop.WriteStructToStream(stream, info);
            }

            stream.WriteByte((Byte)CraftInfoList.Count);
            foreach (var info in CraftInfoList)
            {
                Interop.WriteStructToStream(stream, info.Info);
                EncodedStringUtil.WriteStringToStream(stream, info.Name, encoding);
                EncodedStringUtil.WriteStringToStream(stream, info.Description, encoding);
            }

            Interop.WriteStructToStream(stream, RunAway);
            stream.WriteByte(Reserve);

            EncodedStringUtil.WriteStringToStream(stream, Name, encoding);
            EncodedStringUtil.WriteStringToStream(stream, Description, encoding);

            return(stream.ToArray());
        }
示例#3
0
        static Int32 GetObjectSize(Object value)
        {
            Assert.IsNotNull(value, nameof(value));

            if (value is Bytecode.Instruction instruction)
            {
                return(instruction.GetSize());
            }

            if (value is String)
            {
                return(EncodedStringUtil.GetSize((String)value));
            }

            if (value is FileHeaders.SCENARIO_BATTLESEPITH)
            {
                return(System.Runtime.InteropServices.Marshal.SizeOf <FileHeaders.SCENARIO_BATTLESEPITH>());
            }

            throw new Exception();
        }
示例#4
0
        public Byte[] Write(Encoding encoding)
        {
            Assert.IsNotNull(encoding, nameof(encoding));

            var memstream = new MemoryStream(1024);

            foreach (var item in FileMap)
            {
                memstream.Position = item.Key;

                if (item.Value is FileHeaders.SCENARIO_HEADER header)
                {
                    var bytes = Interop.GetBytesOfStruct(ref header);
                    memstream.Write(bytes, 0, bytes.Length);
                }
                else if (item.Value is List <FileHeaders.SCENARIO_CHIP> chiplist)
                {
                    for (var i = 0; i != chiplist.Count; ++i)
                    {
                        var obj   = chiplist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is List <FileHeaders.SCENARIO_NPC> npclist)
                {
                    for (var i = 0; i != npclist.Count; ++i)
                    {
                        var obj   = npclist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is List <FileHeaders.SCENARIO_MONSTER> monsterlist)
                {
                    for (var i = 0; i != monsterlist.Count; ++i)
                    {
                        var obj   = monsterlist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is List <FileHeaders.SCENARIO_EVENT> eventlist)
                {
                    for (var i = 0; i != eventlist.Count; ++i)
                    {
                        var obj   = eventlist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is List <FileHeaders.SCENARIO_ACTOR> actorlist)
                {
                    for (var i = 0; i != actorlist.Count; ++i)
                    {
                        var obj   = actorlist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is List <FileHeaders.SCENARIO_PLACENAME> placenamelist)
                {
                    for (var i = 0; i != placenamelist.Count; ++i)
                    {
                        var obj   = placenamelist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is List <FileHeaders.SCENARIO_CHIPFRAMEINFO> chipframelist)
                {
                    for (var i = 0; i != chipframelist.Count; ++i)
                    {
                        var obj   = chipframelist[i];
                        var bytes = FileHeaders.SCENARIO_CHIPFRAMEINFO.Write(obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is List <UInt32> offsetlist)
                {
                    for (var i = 0; i != offsetlist.Count; ++i)
                    {
                        var obj   = offsetlist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is String str)
                {
                    var bytes = EncodedStringUtil.GetBytes(str, encoding);
                    memstream.Write(bytes, 0, bytes.Length);
                }
                else if (item.Value is FileHeaders.SCENARIO_BATTLE battle)
                {
                    var bytes = Interop.GetBytesOfStruct(ref battle);
                    memstream.Write(bytes, 0, bytes.Length);
                }
                else if (item.Value is FileHeaders.SCENARIO_BATTLEMONSTERINFO)
                {
                    var obj   = (FileHeaders.SCENARIO_BATTLEMONSTERINFO)item.Value;
                    var bytes = Interop.GetBytesOfStruct(ref obj);
                    memstream.Write(bytes, 0, bytes.Length);
                }
                else if (item.Value is List <FileHeaders.SCENARIO_BATTLEMONSTERPOSITION> positionlist)
                {
                    for (var i = 0; i != positionlist.Count; ++i)
                    {
                        var obj   = positionlist[i];
                        var bytes = Interop.GetBytesOfStruct(ref obj);
                        memstream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (item.Value is Bytecode.Instruction instruction)
                {
                    var bytes = new Byte[instruction.GetSize()];
                    instruction.Write(encoding, bytes, 0);
                    memstream.Write(bytes, 0, bytes.Length);
                }
                else if (item.Value is FileHeaders.SCENARIO_ATBONUS atbonus)
                {
                    var bytes = Interop.GetBytesOfStruct(ref atbonus);
                    memstream.Write(bytes, 0, bytes.Length);
                }
                else if (item.Value is FileHeaders.SCENARIO_BATTLESEPITH sepith)
                {
                    var bytes = Interop.GetBytesOfStruct(ref sepith);
                    memstream.Write(bytes, 0, bytes.Length);
                }
                else
                {
                    throw new Exception();
                }
            }

            return(memstream.ToArray());
        }