[PLUS] CatalogIndex clean up and sub pages fix (done properly).

Damien

Don't need glasses if you can C#
Feb 26, 2012
426
642
I've took the time to clean up one of the worst written composers in Plus, which causes alot of problems for people adding sub pages to categories in the catalog, or sub pages of sub pages. This "fix" or clean up code allows you to add as many sub pages as you like, as well as not foreaching the catalog pages multiple times (for counts ext.). But enough of that, let's get cleaning :D.

Firstly in CatalogManager.cs find this code:
Code:
public ICollection<CatalogPage> GetPages()
{
    return _pages.Values;
}

Changing it to this:
Code:
public ICollection<CatalogPage> GetPages(GameClient session, int pageId)
{
    List<CatalogPage> pages = new List<CatalogPage>();
    foreach (CatalogPage page in this._pages.Values)
    {
        if (page.ParentId != pageId || page.MinimumRank > session.GetHabbo().Rank || (page.MinimumVIP > session.GetHabbo().VIPRank && session.GetHabbo().Rank == 1))
        {
            continue;
        }
        pages.Add(page);
    }
    return pages;
}


Secondly in GetCatalogIndexEvent.cs find this code:
Code:
session.SendPacket(new CatalogIndexComposer(session, PlusEnvironment.GetGame().GetCatalog().GetPages()));

Changing it to this:
Code:
session.SendPacket(new CatalogIndexComposer(session, PlusEnvironment.GetGame().GetCatalog().GetPages(session, -1)));


And lastly in CatalogIndexComposer.cs replace the entire class with this:
Code:
public class CatalogIndexComposer : ServerPacket
{
    public CatalogIndexComposer(GameClient session, ICollection<CatalogPage> pages)
        : base(ServerPacketHeader.CatalogIndexMessageComposer)
    {
        base.WriteBoolean(true);
        base.WriteInteger(0);
        base.WriteInteger(-1);
        base.WriteString("root");
        base.WriteString("");
        base.WriteInteger(0);

        base.WriteInteger(pages.Count);
        foreach (CatalogPage page in pages)
        {
            Append(session, page);
        }

        base.WriteBoolean(false);
        base.WriteString("NORMAL");
    }

    public void Append(GameClient session, CatalogPage page)
    {
        ICollection<CatalogPage> pages = PlusEnvironment.GetGame().GetCatalog().GetPages(session, page.Id);

        base.WriteBoolean(page.Visible);
        base.WriteInteger(page.Icon);
        base.WriteInteger(page.Enabled ? page.Id : -1);
        base.WriteString(page.PageLink);
        base.WriteString(page.Caption);

        base.WriteInteger(page.ItemOffers.Count);
        foreach (int key in page.ItemOffers.Keys)
        {
            base.WriteInteger(key);
        }

        base.WriteInteger(pages.Count);
        foreach (CatalogPage nextPage in pages)
        {
            Append(session, nextPage);
        }
    }
}


Now we're all done, enjoy, love you all, peace, dab emoji.
@Muff for helping test.
@Dolan for requesting this in the first place.
@JynX cause he's just sexy.
 

treebeard

Member
Jan 16, 2018
317
173
I've took the time to clean up one of the worst written composers in Plus, which causes alot of problems for people adding sub pages to categories in the catalog, or sub pages of sub pages. This "fix" or clean up code allows you to add as many sub pages as you like, as well as not foreaching the catalog pages multiple times (for counts ext.). But enough of that, let's get cleaning :D.

Firstly in CatalogManager.cs find this code:
Code:
public ICollection<CatalogPage> GetPages()
{
    return _pages.Values;
}

Changing it to this:
Code:
public ICollection<CatalogPage> GetPages(GameClient session, int pageId)
{
    List<CatalogPage> pages = new List<CatalogPage>();
    foreach (CatalogPage page in this._pages.Values)
    {
        if (page.ParentId != pageId || page.MinimumRank > session.GetHabbo().Rank || (page.MinimumVIP > session.GetHabbo().VIPRank && session.GetHabbo().Rank == 1))
        {
            continue;
        }
        pages.Add(page);
    }
    return pages;
}


Secondly in GetCatalogIndexEvent.cs find this code:
Code:
session.SendPacket(new CatalogIndexComposer(session, PlusEnvironment.GetGame().GetCatalog().GetPages()));

Changing it to this:
Code:
session.SendPacket(new CatalogIndexComposer(session, PlusEnvironment.GetGame().GetCatalog().GetPages(session, -1)));


And lastly in CatalogIndexComposer.cs replace the entire class with this:
Code:
public class CatalogIndexComposer : ServerPacket
{
    public CatalogIndexComposer(GameClient session, ICollection<CatalogPage> pages)
        : base(ServerPacketHeader.CatalogIndexMessageComposer)
    {
        base.WriteBoolean(true);
        base.WriteInteger(0);
        base.WriteInteger(-1);
        base.WriteString("root");
        base.WriteString("");
        base.WriteInteger(0);

        base.WriteInteger(pages.Count);
        foreach (CatalogPage page in pages)
        {
            Append(session, page);
        }

        base.WriteBoolean(false);
        base.WriteString("NORMAL");
    }

    public void Append(GameClient session, CatalogPage page)
    {
        ICollection<CatalogPage> pages = PlusEnvironment.GetGame().GetCatalog().GetPages(session, page.Id);

        base.WriteBoolean(page.Visible);
        base.WriteInteger(page.Icon);
        base.WriteInteger(page.Enabled ? page.Id : -1);
        base.WriteString(page.PageLink);
        base.WriteString(page.Caption);

        base.WriteInteger(page.ItemOffers.Count);
        foreach (int key in page.ItemOffers.Keys)
        {
            base.WriteInteger(key);
        }

        base.WriteInteger(pages.Count);
        foreach (CatalogPage nextPage in pages)
        {
            Append(session, nextPage);
        }
    }
}


Now we're all done, enjoy, love you all, peace, dab emoji.
@Muff for helping test.
@Dolan for requesting this in the first place.
@JynX cause he's just sexy.

WOW, you are an amazing contributor. I was literally just messing around with this last week in an attempt to be able to add more tiers of sub-pages.
Thank you so much! ^.^
 

Rebel

Spilling the tea, can't you read?🍵
Dec 24, 2015
186
161
Thank you, while I was organizing my catalogue this helped a lot appreciate it fam
 

Ellu

Donator
Mar 8, 2018
42
65
@Damien I'm disconnecting when i click the items

ezgif-5-50285d67ad.gif


EDIT:
it doesn't really matter what item you click in the catalog, you will disconnect.
 
Last edited:

treebeard

Member
Jan 16, 2018
317
173
Oh for some reason I disconnect when clicking any of the sub-tiers
Edit: I tried playing around with this for a bit but to no avail. @Damien
 
Last edited:

Bjork

Member
Feb 7, 2012
73
29
@Damien I'm disconnecting when i click the items

ezgif-5-50285d67ad.gif


EDIT:
it doesn't really matter what item you click in the catalog, you will disconnect.

Check your GetCatalogIndexEvent.cs, he needs to be like this. I had the same problem and figured out i deleted one line when i copied/pasted the code.

 

Ellu

Donator
Mar 8, 2018
42
65
Check your GetCatalogIndexEvent.cs, he needs to be like this. I had the same problem and figured out i deleted one line when i copied/pasted the code.

Thank you so much, it works.
 

Bran

mediocre graphics artist
Mar 13, 2017
1,727
1,530
i don't even have this in my GetCatalogIndexEvent

Code:
session.SendPacket(new CatalogIndexComposer(session, PlusEnvironment.GetGame().GetCatalog().GetPages()));
 

Zenuyasha

</Dev>
Dec 5, 2016
170
48
i don't even have this in my GetCatalogIndexEvent

Code:
session.SendPacket(new CatalogIndexComposer(session, PlusEnvironment.GetGame().GetCatalog().GetPages()));
Super bit late but might help someone in the future if you don't have that code in your GetCatalogIndexEvent.cs It's
C#:
session.SendMessage(new CatalogIndexComposer(Session, PlusEnvironment.GetGame().GetCatalog().GetPages()));
 

Bran

mediocre graphics artist
Mar 13, 2017
1,727
1,530
Super bit late but might help someone in the future if you don't have that code in your GetCatalogIndexEvent.cs It's
C#:
session.SendMessage(new CatalogIndexComposer(Session, PlusEnvironment.GetGame().GetCatalog().GetPages()));
this was over a year ago lmao, it was done on the day i posted this
 

Users who are viewing this thread

Top