Exemplo n.º 1
0
        public static PartyMemberId FromDisk(int disk, AssetMapping mapping)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }


            var(enumType, enumValue) = mapping.IdToEnum(new PartyMemberId(AssetType.Party, disk));
            return((PartyMemberId)AssetMapping.Global.EnumToId(enumType, enumValue));
        }
Exemplo n.º 2
0
 public SpellData Serdes(SpellData existing, AssetInfo config, AssetMapping mapping, ISerializer s)
 {
     if (config == null)
     {
         throw new ArgumentNullException(nameof(config));
     }
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     return(SpellData.Serdes(config.AssetId, existing, s));
 }
Exemplo n.º 3
0
 public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (config == null)
     {
         throw new ArgumentNullException(nameof(config));
     }
     return(WaveLib.Serdes(null, s));
 }
Exemplo n.º 4
0
 public SpellData Serdes(SpellData existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
 {
     if (info == null)
     {
         throw new ArgumentNullException(nameof(info));
     }
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     return(SpellData.Serdes(existing, info, s));
 }
Exemplo n.º 5
0
 public WaveLib Serdes(WaveLib existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (info == null)
     {
         throw new ArgumentNullException(nameof(info));
     }
     return(WaveLib.Serdes(existing, s));
 }
Exemplo n.º 6
0
        public static WaveLibraryId SerdesU8(string name, WaveLibraryId id, AssetMapping mapping, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }

            byte diskValue = (byte)id.ToDisk(mapping);

            diskValue = s.UInt8(name, diskValue);
            return(FromDisk(diskValue, mapping));
        }
Exemplo n.º 7
0
        public static WordId SerdesU16BE(string name, WordId id, AssetMapping mapping, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }

            ushort diskValue = (ushort)id.ToDisk(mapping);

            diskValue = s.UInt16BE(name, diskValue);
            return(FromDisk(diskValue, mapping));
        }
Exemplo n.º 8
0
 public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (config == null)
     {
         throw new ArgumentNullException(nameof(config));
     }
     return(new AlbionSample(s.ByteArray(null, null, (int)s.BytesRemaining)));
 }
Exemplo n.º 9
0
 public AlbionPalette Serdes(AlbionPalette existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (info == null)
     {
         throw new ArgumentNullException(nameof(info));
     }
     return(AlbionPalette.Serdes(existing, info, s));
 }
Exemplo n.º 10
0
 public AlbionSample Serdes(AlbionSample existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (info == null)
     {
         throw new ArgumentNullException(nameof(info));
     }
     return(s.IsWriting() ? Write(existing, s) : Read(s));
 }
Exemplo n.º 11
0
        static void MergeTypesToMapping(AssetMapping mapping, AssetConfig config, string assetConfigPath)
        {
            foreach (var assetType in config.Types)
            {
                var enumType = Type.GetType(assetType.Key);
                if (enumType == null)
                {
                    throw new InvalidOperationException($"Could not load enum type \"{assetType.Key}\" defined in \"{assetConfigPath}\"");
                }

                mapping.RegisterAssetType(assetType.Key, assetType.Value.AssetType);
            }
        }
Exemplo n.º 12
0
 public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     if (config == null)
     {
         throw new ArgumentNullException(nameof(config));
     }
     s.Seek(WordLength * config.SubAssetId);
     return(s.FixedLengthString(null, null, WordLength));
 }
Exemplo n.º 13
0
        public object Serdes(object existing, AssetInfo config, AssetMapping mapping, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            var bytes = s.ByteArray(null, null, (int)s.BytesRemaining);
            var text  = Encoding.UTF8.GetString(bytes);

            return
                (JsonConvert.DeserializeObject <IDictionary <Base.UAlbionString, string> >(text)
                 .ToDictionary(x => TextId.From(x.Key), x => x.Value));
        }
Exemplo n.º 14
0
        public BlockList Serdes(BlockList existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
        {
            if (info == null) throw new ArgumentNullException(nameof(info));
            if (s == null) throw new ArgumentNullException(nameof(s));
            if (jsonUtil == null) throw new ArgumentNullException(nameof(jsonUtil));

            if (s.IsWriting())
            {
                if (existing == null) throw new ArgumentNullException(nameof(existing));

                var blockListId = (BlockListId)info.AssetId;
                var tilesetId = blockListId.ToTileset();

                var tilesetPattern = info.Get(AssetProperty.TilesetPattern, "../Tilesets/{0}_{2}.tsx");
                var tilesetPath = string.Format(CultureInfo.InvariantCulture,
                    tilesetPattern,
                    tilesetId.Id,
                    0,
                    ConfigUtil.AssetName(tilesetId));

                var tileset = new Tileset
                {
                    Filename = tilesetPath,
                    TileWidth = 16,
                    TileHeight = 16,
                };

                PackedChunks.Pack(s, existing.Count, stampNumber =>
                {
                    if (existing[stampNumber].Width == 0 || existing[stampNumber].Height == 0)
                        return Array.Empty<byte>();
                    var stamp = new Stamp(stampNumber, existing[stampNumber], tileset);
                    return Encoding.UTF8.GetBytes(stamp.Serialize(jsonUtil));
                });

                return existing;
            }

            var list = new BlockList();
            foreach (var (jsonBytes, _) in PackedChunks.Unpack(s))
            {
                var stamp = Stamp.Parse(jsonBytes, jsonUtil);
                var block = stamp != null ? stamp.ToBlock() : new Block();
                list.Add(block);
            }

            while (list.Count < BlockList.MaxCount)
                list.Add(new Block());

            return list;
        }
Exemplo n.º 15
0
 public static DoorEvent Serdes(DoorEvent e, AssetMapping mapping, ISerializer s, TextId textSourceId)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     e ??= new DoorEvent(textSourceId);
     e.PickDifficulty = s.UInt8(nameof(PickDifficulty), e.PickDifficulty);
     e.Key            = ItemId.SerdesU16(nameof(Key), e.Key, AssetType.Item, mapping, s);
     e.OpenedText     = s.UInt8(nameof(OpenedText), e.OpenedText);
     e.UnlockedText   = s.UInt8(nameof(UnlockedText), e.UnlockedText);
     e.DoorId         = DoorId.SerdesU16(nameof(DoorId), e.DoorId, mapping, s); // Usually 100+
     return(e);
 }
Exemplo n.º 16
0
    public object Serdes(object existing, AssetInfo info, AssetMapping mapping, ISerializer s, IJsonUtil jsonUtil)
    {
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        if (jsonUtil == null)
        {
            throw new ArgumentNullException(nameof(jsonUtil));
        }
        var bytes = s.Bytes(null, null, (int)s.BytesRemaining);

        return(jsonUtil.Deserialize <IntStringDictionary>(bytes));
    }
Exemplo n.º 17
0
 public static ChestEvent Serdes(ChestEvent e, AssetMapping mapping, ISerializer s, TextId textSourceId)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     e ??= new ChestEvent(textSourceId);
     e.PickDifficulty = s.UInt8(nameof(PickDifficulty), e.PickDifficulty);
     e.KeyItemId      = ItemId.SerdesU16(nameof(KeyItemId), e.KeyItemId, AssetType.Item, mapping, s);
     e.UnlockedTextId = s.UInt8(nameof(UnlockedTextId), e.UnlockedTextId);
     e.InitialTextId  = s.UInt8(nameof(InitialTextId), e.InitialTextId);
     e.ChestId        = ChestId.SerdesU16(nameof(ChestId), e.ChestId, mapping, s);
     return(e);
 }
Exemplo n.º 18
0
 public static VisitedEventList Serdes(int _, VisitedEventList c, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     c ??= new VisitedEventList();
     c.Size      = s.UInt32(nameof(Size), c.Size);
     c.NumChunks = s.UInt16(nameof(NumChunks), c.NumChunks);
     ApiUtil.Assert(c.NumChunks == c.Size / VisitedEvent.SizeOnDisk);
     c.Contents ??= new VisitedEvent[(c.Size - 2) / VisitedEvent.SizeOnDisk];
     s.List(nameof(c.Contents), c.Contents, mapping, c.Contents.Length, VisitedEvent.Serdes);
     return(c);
 }
Exemplo n.º 19
0
 public static MapChange Serdes(int i, MapChange u, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     u ??= new MapChange();
     u.X          = s.UInt8(nameof(X), u.X);
     u.Y          = s.UInt8(nameof(Y), u.Y);
     u.ChangeType = s.EnumU8(nameof(ChangeType), u.ChangeType);
     u.Unk3       = s.EnumU8(nameof(Unk3), u.Unk3);
     u.Value      = s.UInt16(nameof(Value), u.Value);
     u.MapId      = MapId.SerdesU16(nameof(Overlay), u.MapId, mapping, s);
     return(u);
 }
Exemplo n.º 20
0
    public static TextId FromDisk(AssetType type, int disk, AssetMapping mapping)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }

        if (!(type == AssetType.None || type >= AssetType.EventText && type <= AssetType.Word || type == AssetType.Special))
        {
            throw new ArgumentOutOfRangeException($"Tried to construct a TextId with a type of {type}");
        }

        var(enumType, enumValue) = mapping.IdToEnum(new TextId(type, disk));
        return((TextId)AssetMapping.Global.EnumToId(enumType, enumValue));
    }
Exemplo n.º 21
0
 public static SetPartyLeaderEvent Serdes(SetPartyLeaderEvent e, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     e ??= new SetPartyLeaderEvent();
     e.Unk2          = s.UInt8(nameof(Unk2), e.Unk2);
     e.Unk3          = s.UInt8(nameof(Unk3), e.Unk3);
     e.Unk4          = s.UInt8(nameof(Unk4), e.Unk4);
     e.Unk5          = s.UInt8(nameof(Unk5), e.Unk5);
     e.PartyMemberId = PartyMemberId.SerdesU16(nameof(PartyMemberId), e.PartyMemberId, mapping, s);
     e.Unk8          = s.UInt16(nameof(Unk8), e.Unk8);
     return(e);
 }
Exemplo n.º 22
0
    public static CharacterId FromDisk(AssetType type, int disk, AssetMapping mapping)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }

        if (!(type == AssetType.None || type >= AssetType.Monster && type <= AssetType.Party))
        {
            throw new ArgumentOutOfRangeException($"Tried to construct a CharacterId with a type of {type}");
        }

        var(enumType, enumValue) = mapping.IdToEnum(new CharacterId(type, disk));
        return((CharacterId)AssetMapping.Global.EnumToId(enumType, enumValue));
    }
Exemplo n.º 23
0
        static void BuildEventHash(MapId mapId, IScriptable scriptable, AssetMapping mapping)
        {
            if (scriptable.Events == null)
            {
                return;
            }

            scriptable.EventBytes = FormatUtil.SerializeToBytes(s =>
            {
                for (ushort i = 0; i < scriptable.Events.Count; i++)
                {
                    scriptable.Events[i] = EventNode.Serdes(i, scriptable.Events[i], s, mapId, mapId.ToMapText(), mapping);
                }
            });
        }
Exemplo n.º 24
0
        public static SimpleChestEvent Serdes(SimpleChestEvent e, AssetMapping mapping, ISerializer s)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            e ??= new SimpleChestEvent();
            e.ChestType = s.EnumU8(nameof(ChestType), e.ChestType);
            uint padding = s.UInt32(nameof(padding), 0);

            ApiUtil.Assert(padding == 0);
            e.ItemId = ItemId.SerdesU16(nameof(e.ItemId), e.ItemId, AssetType.Item, mapping, s);
            e.Amount = s.UInt16(nameof(Amount), e.Amount);
            return(e);
        }
Exemplo n.º 25
0
    public static SpriteId FromDisk(AssetType type, int disk, AssetMapping mapping)
    {
        if (mapping == null)
        {
            throw new ArgumentNullException(nameof(mapping));
        }

        if (!(type >= AssetType.None && type <= AssetType.WallOverlay))
        {
            throw new ArgumentOutOfRangeException($"Tried to construct a SpriteId with a type of {type}");
        }

        var(enumType, enumValue) = mapping.IdToEnum(new SpriteId(type, disk));
        return((SpriteId)AssetMapping.Global.EnumToId(enumType, enumValue));
    }
Exemplo n.º 26
0
 public static PlayAnimationEvent Serdes(PlayAnimationEvent e, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     e ??= new PlayAnimationEvent();
     e.VideoId = VideoId.SerdesU8(nameof(VideoId), e.VideoId, mapping, s);
     e.X       = s.UInt8(nameof(X), e.X);
     e.Y       = s.UInt8(nameof(Y), e.Y);
     e.Unk4    = s.UInt8(nameof(Unk4), e.Unk4);
     e.Unk5    = s.UInt8(nameof(Unk5), e.Unk5);
     e.Unk6    = s.UInt16(nameof(Unk6), e.Unk6);
     e.Unk8    = s.UInt16(nameof(Unk8), e.Unk8);
     return(e);
 }
Exemplo n.º 27
0
    public static EventExchange Setup(
        AssetMapping mapping,
        IFileSystem disk,
        IJsonUtil jsonUtil,
        GeneralConfig generalConfig,
        GeneralSettings settings,
        CoreConfig coreConfig,
        GameConfig gameConfig)
    {
        var configAndSettingsTask = Task.FromResult((generalConfig, settings));
        var coreConfigTask        = Task.FromResult(coreConfig);
        var gameConfigTask        = Task.FromResult(gameConfig);
        var task = SetupCore(mapping, disk, jsonUtil, configAndSettingsTask, coreConfigTask, gameConfigTask);

        return(task.Result.Item1);
    }
Exemplo n.º 28
0
    public AssetConverter(AssetMapping mapping, IFileSystem disk, IJsonUtil jsonUtil, string[] fromMods, string toMod)
    {
        if (disk == null)
        {
            throw new ArgumentNullException(nameof(disk));
        }
        if (jsonUtil == null)
        {
            throw new ArgumentNullException(nameof(jsonUtil));
        }

        var baseDir = ConfigUtil.FindBasePath(disk);

        (_from, _fromExchange, _fromLoaderRegistry) = BuildModApplier(baseDir, fromMods, disk, jsonUtil, mapping);
        (_to, _toExchange, _toLoaderRegistry)       = BuildModApplier(baseDir, new[] { toMod }, disk, jsonUtil, mapping);
    }
Exemplo n.º 29
0
 public static Overlay Serdes(int _, Overlay o, AssetMapping mapping, ISerializer s)
 {
     if (s == null)
     {
         throw new ArgumentNullException(nameof(s));
     }
     o ??= new Overlay();
     o.SpriteId        = SpriteId.SerdesU16(nameof(o.SpriteId), o.SpriteId, AssetType.WallOverlay, mapping, s);
     o.AnimationFrames = s.UInt8(nameof(o.AnimationFrames), o.AnimationFrames);
     o.WriteZero       = s.UInt8(nameof(o.WriteZero), o.WriteZero);
     o.XOffset         = s.UInt16(nameof(o.XOffset), o.XOffset);
     o.YOffset         = s.UInt16(nameof(o.YOffset), o.YOffset);
     o.Width           = s.UInt16(nameof(o.Width), o.Width);
     o.Height          = s.UInt16(nameof(o.Height), o.Height);
     return(o);
 }
Exemplo n.º 30
0
    public static ChangeFoodEvent Serdes(ChangeFoodEvent e, AssetMapping mapping, ISerializer s)
    {
        if (s == null)
        {
            throw new ArgumentNullException(nameof(s));
        }
        e ??= new ChangeFoodEvent();
        e.Operation = s.EnumU8(nameof(Operation), e.Operation);
        e.Unk3      = s.UInt8(nameof(Unk3), e.Unk3);
        int zeroed = s.UInt8(null, 0); s.Assert(zeroed == 0, "ChangeFoodEvent: Expected byte 4 to be 0");

        e.PartyMemberId = PartyMemberId.SerdesU8(nameof(PartyMemberId), e.PartyMemberId, mapping, s);
        zeroed          = s.UInt16(null, 0); s.Assert(zeroed == 0, "ChangeFoodEvent: Expected word 6 to be 0"); // TODO: Can be 1
        e.Amount        = s.UInt16(nameof(Amount), e.Amount);
        return(e);
    }