예제 #1
0
 public static MobInfo Parse(WZProperty stringWz)
 {
     if (stringWz == null)
     {
         return(null);
     }
     else
     {
         int mobId = int.Parse(stringWz.NameWithoutExtension);
         if (stringWz.FileContainer.Collection is MSPackageCollection)
         {
             MSPackageCollection collection = (MSPackageCollection)stringWz.FileContainer.Collection;
             if (collection.MobMeta.ContainsKey(mobId))
             {
                 Tuple <string, int, bool> mobMeta = collection.MobMeta[mobId];
                 return(new MobInfo(
                            mobId,
                            stringWz.ResolveForOrNull <string>("name"),
                            mobMeta.Item1,
                            mobMeta.Item2,
                            mobMeta.Item3
                            ));
             }
         }
         return(new MobInfo(
                    mobId,
                    stringWz.ResolveForOrNull <string>("name")
                    ));
     }
 }
예제 #2
0
        public static Quest GetQuest(WZProperty questWz, int questId)
        {
            QuestRewards[]      rewards      = QuestRewards.Parse(questWz.Resolve($"Act/{questId}")) ?? new QuestRewards[0];
            QuestRequirements[] requirements = QuestRequirements.Parse(questWz.Resolve($"Check/{questId}")) ?? new QuestRequirements[0];
            Quest quest = Quest.Parse(questWz.Resolve($"QuestInfo/{questId}"));

            if (quest == null)
            {
                return(null);
            }

            quest.RequirementToComplete = requirements?.Where(b => b != null && b.State == QuestState.Complete).FirstOrDefault();
            quest.RequirementToStart    = requirements?.Where(b => b != null && b.State == QuestState.Start).FirstOrDefault();
            quest.RewardOnStart         = rewards?.Where(b => b != null && b.State == QuestState.Start).FirstOrDefault();
            quest.RewardOnComplete      = rewards?.Where(b => b != null && b.State == QuestState.Complete).FirstOrDefault();
            if (questWz.FileContainer.Collection is MSPackageCollection)
            {
                MSPackageCollection collection = (MSPackageCollection)questWz.FileContainer.Collection;
                if (collection.AvailableOnCompleteTable.ContainsKey(quest.Id))
                {
                    quest.QuestsAvailableOnComplete = collection.AvailableOnCompleteTable[quest.Id];
                }
            }

            return(quest);
        }
예제 #3
0
        public IActionResult QueryImage(Region region, string version, string path)
        {
            MSPackageCollection wz   = _wzFactory.GetWZ(region, version);
            WZProperty          prop = wz.Resolve(path);

            if (prop == null)
            {
                return(NotFound());
            }

            if (prop is IWZPropertyVal <Image <Rgba32> > )
            {
                return(File(((IWZPropertyVal <Image <Rgba32> >)prop).Value.ImageToByte(Request), "image/png"));
            }
            return(NotFound());
        }
예제 #4
0
        public IActionResult Query(Region region, string version, string path)
        {
            MSPackageCollection wz = _wzFactory.GetWZ(region, version);

            if (string.IsNullOrEmpty(path))
            {
                return(Json(new
                {
                    children = wz.Packages.Keys.ToArray(),
                    location = wz.Folder,
                    version = wz.MapleVersion?.MapleVersionId,
                    type = -1
                }));
            }

            WZProperty prop = wz.Resolve(path);

            if (prop == null)
            {
                return(NotFound());
            }

            if (prop is IWZPropertyVal)
            {
                return(Json(new
                {
                    children = prop.Children.Select(c => c.Name),
                    type = prop.Type,
                    value = prop.Type == PropertyType.Canvas ? prop.ResolveForOrNull <Image <Rgba32> >() : ((IWZPropertyVal)prop).GetValue()
                }));
            }

            return(Json(new
            {
                children = prop.Children.Select(c => c.Name),
                type = prop.Type
            }));
        }
예제 #5
0
        public IActionResult Export(Region region, string version, string path, [FromQuery] bool rawImage = false)
        {
            MSPackageCollection wz   = _wzFactory.GetWZ(region, version);
            WZProperty          prop = wz.Resolve(path);

            if (prop == null)
            {
                return(NotFound());
            }
            if (prop.Type == PropertyType.Directory)
            {
                return(Forbid());
            }

            Queue <WZProperty> propQueue = new Queue <WZProperty>();

            propQueue.Enqueue(prop);

            if (rawImage && rawImage)
            {
                using (WZReader reader = prop.FileContainer.GetContentReader(null, prop.Resolve()))
                {
                    reader.BaseStream.Seek(prop.Offset, SeekOrigin.Begin);
                    return(File(reader.ReadBytes((int)prop.Size), "wizet/img", $"{prop.NameWithoutExtension}.img"));
                }
            }

            using (MemoryStream mem = new MemoryStream())
            {
                using (ZipArchive archive = new ZipArchive(mem, ZipArchiveMode.Create, true))
                {
                    while (propQueue.TryDequeue(out WZProperty entry))
                    {
                        byte[] data      = null;
                        string extension = null;
                        if (entry.Type == PropertyType.Audio)
                        {
                            data      = (byte[])((IWZPropertyVal <byte[]>)entry).Value;
                            extension = "mp3";
                        }
                        else if (entry.Type == PropertyType.Canvas)
                        {
                            data      = entry.ResolveForOrNull <Image <Rgba32> >()?.ImageToByte(Request, false, null, false);
                            extension = "png";
                        }

                        if (data != null)
                        {
                            ZipArchiveEntry zipEntry = archive.CreateEntry(entry.Path + '.' + extension, CompressionLevel.Optimal);
                            using (Stream zipEntryData = zipEntry.Open())
                            {
                                zipEntryData.Write(data, 0, data.Length);
                                zipEntryData.Flush();
                            }
                        }

                        foreach (WZProperty child in entry.Children)
                        {
                            propQueue.Enqueue(child);
                        }
                    }
                }

                return(File(mem.ToArray(), "application/zip", "export.zip"));
            }
        }
예제 #6
0
        public static void Main(string[] args)
        {
            Console.WriteLine($"Console Arguments: {string.Join(",", args)}");

            Stopwatch watch = Stopwatch.StartNew();

            ILoggerFactory              logging                 = LoggerFactory.Create(builder => builder.AddConsole(options => options.LogToStandardErrorThreshold = LogLevel.Trace));
            ILogger <Package>           packageLogger           = logging.CreateLogger <Package>();
            ILogger <PackageCollection> packageCollectionLogger = logging.CreateLogger <PackageCollection>();
            ILogger <VersionGuesser>    versionGuesserLogger    = logging.CreateLogger <VersionGuesser>();
            ILogger <WZReader>          readerLogging           = logging.CreateLogger <WZReader>();

            MSPackageCollection.Logger  = logging.CreateLogger <MSPackageCollection>();
            WZFactory.Logger            = logging.CreateLogger <WZFactory>();
            WZAppSettingsFactory.Logger = logging.CreateLogger <WZAppSettingsFactory>();
            PackageCollection.Logging   = (s) => packageCollectionLogger.LogInformation(s);
            VersionGuesser.Logging      = (s) => versionGuesserLogger.LogInformation(s);
            Package.Logging             = (s) => packageLogger.LogInformation(s);

            WZProperty.SpecialUOL.Add("version", (uol, version) =>
            {
                string path            = uol.Path;
                MSPackageCollection wz = WZFactory.GetWZFromCache(uol.FileContainer.Collection.WZRegion, version);
                if (wz != null)
                {
                    return(wz.Resolve(path));
                }

                using (ApplicationDbContext dbCtx = new ApplicationDbContext())
                {
                    WZFactory wzFactory = new WZFactory(dbCtx);
                    return(wzFactory.GetWZ(uol.FileContainer.Collection.WZRegion, version).Resolve(path));
                }
            });

            //WZProperty.ChildrenMutate = (i) =>
            //{
            //    return i.Select(c =>
            //    {
            //        if (c.Type != PropertyType.Lua) return c;

            //        string luaVal = c.ResolveForOrNull<string>();
            //        if (!luaVal.StartsWith("!")) return c;

            //        string specialType = luaVal.Substring(1, luaVal.IndexOf(':') - 1);
            //        if (WZProperty.SpecialUOL.ContainsKey(specialType))
            //            return WZProperty.SpecialUOL[specialType](c, luaVal.Substring(specialType.Length + 2));
            //        else throw new InvalidOperationException("Unable to follow Special UOL, as there is no defined route");
            //    });
            //};

            readerLogging.LogDebug("Initializing Keys");
            WZReader.InitializeKeys();
            readerLogging.LogDebug("Done");

            //WZFactory.LoadAllWZ();

            ILogger prog = logging.CreateLogger <Program>();

            watch.Stop();
            prog.LogInformation($"Starting aspnet kestrel, took {watch.ElapsedMilliseconds}ms to initialize");

            var host = new WebHostBuilder()
                       .UseKestrel(options =>
            {
                options.Limits.MaxConcurrentConnections         = ushort.MaxValue;
                options.Limits.MaxConcurrentUpgradedConnections = ushort.MaxValue;
                options.Limits.MaxRequestLineSize    = ushort.MaxValue;
                options.Limits.MaxRequestBufferSize  = int.MaxValue;
                options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(15);
                options.Limits.KeepAliveTimeout      = TimeSpan.FromSeconds(120);
            })
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseUrls("http://*:5000")
                       .UseStartup <Startup>()
                       .Build();

            host.Run();
        }
예제 #7
0
 public void CloneWZFrom(NeedWZ original)
 {
     WZ      = original.WZ;
     Region  = original.Region;
     Version = original.Version;
 }