Skip to content

Instantly share code, notes, and snippets.

@scottstamp
Last active May 26, 2019 01:47
Show Gist options
  • Save scottstamp/97e93d27741a78939f1e5d44c9964ab6 to your computer and use it in GitHub Desktop.
Save scottstamp/97e93d27741a78939f1e5d44c9964ab6 to your computer and use it in GitHub Desktop.
message structure for a C# Unity game WIP
using System;
namespace Game.Common.Messages.Incoming
{
public class ConfigurationMsg
{
public int ClothSellConversionRate;
public PriceData[] CraftingPrices;
public int HcToScConversionRate;
public int NewLabelDisplayDays;
public int NameChangePrice;
public int PartyCreationPrice;
public int PartyMaxParticipantCount;
public int ReportMaxAmountPerDay;
public int BonusPartyMaxParticipantCount;
public int ExtraLootBoxPrice;
public int AdTimeoutSeconds;
public int TutorialBonusScReward;
public ProductId TutorialMaleClothProductId;
public ProductId TutorialFemaleClothProductId;
public ProductId TutorialColourProductId;
public string[] ActiveFeatureSwitches;
public string HwLandingPageLink;
public ProductId[] SkinColours;
public ProductId DefaultSkinColour;
public ProductId[] DefaultMaleWornItems;
public ProductId[] DefaultFemaleWornItems;
public EquippedColor[] DefaultEquippedColours;
public int DefaultCarpenterBoxHcPrice;
public int FurniSellConversionRate;
public string RoomPictureBucketUrl;
public ConfigurationMsg(HMessage m)
{
/// Brief explanation of protocol:
/// BigEndian
/// all arrays are length-prefixed with a short
///
/// integer = 4 byte encoded
/// short = 2 byte encoded
/// string = char[]
/// enum = single byte { ordinal }, occasionally a short but don't worry about that...
/// bool = 1 byte 0/1
ClothSellConversionRate = m.ReadInteger();
CraftingPrices = new PriceData[m.ReadShort()];
for (int i = 0; i < CraftingPrices.Length; i++)
CraftingPrices[i] = new PriceData()
{
Price = m.ReadInteger(),
Currency = (CurrencyType)m.ReadByte()
};
HcToScConversionRate = m.ReadInteger();
NewLabelDisplayDays = m.ReadInteger();
NameChangePrice = m.ReadInteger();
PartyCreationPrice = m.ReadInteger();
PartyMaxParticipantCount = m.ReadInteger();
ReportMaxAmountPerDay = m.ReadInteger();
BonusPartyMaxParticipantCount = m.ReadInteger();
ExtraLootBoxPrice = m.ReadInteger();
AdTimeoutSeconds = m.ReadInteger();
TutorialBonusScReward = m.ReadInteger();
TutorialMaleClothProductId = new ProductId(m.ReadInteger());
TutorialFemaleClothProductId = new ProductId(m.ReadInteger());
TutorialColourProductId = new ProductId(m.ReadInteger());
ActiveFeatureSwitches = new string[m.ReadShort()];
for (int i = 0; i < ActiveFeatureSwitches.Length; i++)
ActiveFeatureSwitches[i] = m.ReadString();
HwLandingPageLink = m.ReadString();
SkinColours = new ProductId[m.ReadShort()];
for (int i = 0; i < SkinColours.Length; i++)
SkinColours[i] = new ProductId(m.ReadInteger());
DefaultSkinColour = new ProductId(m.ReadInteger());
DefaultMaleWornItems = new ProductId[m.ReadShort()];
for (int i = 0; i < DefaultMaleWornItems.Length; i++)
DefaultMaleWornItems[i] = new ProductId(m.ReadInteger());
DefaultFemaleWornItems = new ProductId[m.ReadShort()];
for (int i = 0; i < DefaultFemaleWornItems.Length; i++)
DefaultFemaleWornItems[i] = new ProductId(m.ReadInteger());
DefaultEquippedColours = new EquippedColor[m.ReadShort()];
for (int i = 0; i < DefaultEquippedColours.Length; i++)
DefaultEquippedColours[i] = new EquippedColor()
{
Id = m.ReadInteger(),
AvatarPart = m.ReadInteger(),
Slot = m.ReadInteger(),
ColorType = m.ReadByte()
};
DefaultCarpenterBoxHcPrice = m.ReadInteger();
FurniSellConversionRate = m.ReadInteger();
RoomPictureBucketUrl = m.ReadString();
}
}
public class PriceData
{
public int Price;
public CurrencyType Currency;
}
public enum CurrencyType
{
Soft,
Hard,
Real
}
public class EquippedColor
{
public int Id;
public int AvatarPart;
public int Slot;
public byte ColorType;
}
public class Id<T> : IEquatable<Id<T>>
{
public T Value { get; }
public Id(T value)
{
Value = value;
}
public bool Equals(Id<T> other)
{
throw new NotImplementedException();
}
}
public class ProductId : Id<int>
{
public ProductId(int value) : base(value)
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment