neptools

Modding tools to Neptunia games
git clone https://git.neptards.moe/neptards/neptools.git
Log | Files | Refs | Submodules | README | LICENSE

expansion.cpp (2009B)


      1 #include "expansion.hpp"
      2 #include "../context.hpp"
      3 #include "../raw_item.hpp"
      4 #include "../cstring_item.hpp"
      5 #include "../../sink.hpp"
      6 
      7 namespace Neptools::Stcm
      8 {
      9 
     10   void ExpansionItem::Header::Validate(FilePosition file_size) const
     11   {
     12 #define VALIDATE(x) LIBSHIT_VALIDATE_FIELD("Stcm::ExpansionItemItem::Header", x)
     13     VALIDATE(name < file_size);
     14     VALIDATE(ptr == 0);
     15     for (const auto& p : pad) VALIDATE(p == 0);
     16 #undef VALIDATE
     17   }
     18 
     19   ExpansionItem::ExpansionItem(Key k, Context& ctx, const Header& hdr)
     20     : Item{k, ctx}, name{Libshit::EmptyNotNull{}}
     21   {
     22     hdr.Validate(ctx.GetSize());
     23 
     24     index = hdr.index;
     25     name = ctx.GetLabelTo(hdr.name);
     26   }
     27 
     28   ExpansionItem& ExpansionItem::CreateAndInsert(ItemPointer ptr)
     29   {
     30     auto x = RawItem::Get<Header>(ptr);
     31     auto& ret = x.ritem.SplitCreate<ExpansionItem>(ptr.offset, x.t);
     32 
     33     MaybeCreate<CStringItem>(ret.name->GetPtr());
     34 
     35     return ret;
     36   }
     37 
     38   void ExpansionItem::Dump_(Sink& sink) const
     39   {
     40     Header hdr{};
     41     hdr.index = index;
     42     hdr.name = ToFilePos(name->GetPtr());
     43     sink.WriteGen(hdr);
     44   }
     45 
     46   void ExpansionItem::Inspect_(std::ostream& os, unsigned indent) const
     47   {
     48     Item::Inspect_(os, indent);
     49     os << "expansion(" << index << ", " << PrintLabel(name) << ")";
     50   }
     51 
     52 
     53   ExpansionsItem& ExpansionsItem::CreateAndInsert(
     54     ItemPointer ptr, uint32_t count)
     55   {
     56     auto& ret = ptr.AsChecked<RawItem>().SplitCreate<ExpansionsItem>(
     57       ptr.offset);
     58     ret.MoveNextToChild(count * sizeof(ExpansionItem::Header));
     59     auto it = ret.GetChildren().begin();
     60 
     61     for (uint32_t i = 0; i < count; ++i)
     62     {
     63       auto lbl = ret.GetContext()->CreateLabelFallback("expansion", *it);
     64       auto& exp = ExpansionItem::CreateAndInsert(lbl->GetPtr());
     65       it = std::next(exp.Iterator());
     66     }
     67     return ret;
     68   }
     69 
     70   void ExpansionsItem::Inspect_(std::ostream& os, unsigned indent) const
     71   {
     72     Item::Inspect_(os, indent);
     73     os << "expansions()";
     74     InspectChildren(os, indent);
     75   }
     76 
     77 }
     78 
     79 #include "expansion.binding.hpp"