Finaltwist

Member
ServUO Version
Publish Unknown
Ultima Expansion
None
Any easy way to do this?

I've had to be pretty creative in the past to do this - i'd like to serialize a type of mobile, but can't use the mobile.name string since they have generated names ... just wondering if anyone has found an easy-ish way to do this...
 
each mobile shoudl have its own Type?

Or do you mean to serialize a connection for example?
If so you can use the serial of the mobile
 
e.g. random item have a type variable that is assigned when its created (from a mobile).
the item can be created with ANY mobile type in the world.

I need the item to retain that psecific mobile type on server restart
each mobile shoudl have its own Type?

Or do you mean to serialize a connection for example?
If so you can use the serial of the mobile
e.g.
public class EssenceBones : Item
{
private Type m_mob;
[CommandProperty( AccessLevel.GameMaster )]
public Type Mob
{
get{ return m_mob; }
set{ m_mob = value; }
}
public static int[] m_Bone = new int[]
{
6921, 6922, 6923, 6924, 6925, 6926, 6927, 6928, 6929, 6930, 6931, 6932,
6933, 6934, 6935, 6936, 6937, 6938, 6939, 6940, 6880, 6881, 6882, 6883,
6884
};
[Constructable]
public EssenceBones( Type moob ) : base( 6921 )
{
m_mob = moob;
Name = "Essence Bones";
ItemID = m_Bone[Utility.Random(m_Bone.Length)];
Weight = 0.1;
}
 
Are you trying to serialize a Type? ie a definition of a thing or you are trying to serialize an already constructed Mobile that is then referenced in EssenceBones?
 
Are you trying to serialize a Type? ie a definition of a thing or you are trying to serialize an already constructed Mobile that is then referenced in EssenceBones?
im trying to serialize a type, the mobile isn't built. the mobile can be built at a later time, all it needs to do is "remember" the mobile type.

For example, is there a way to change the mobile type ToString, save as a string in serialization, and then convert back to mobile type on deserialization?
 
AAAh that explains why im the only one having this problem... im asking for ultima adventures which runs runuo2.7. That method isn't available in serialization. Looks like i'm stuck trying to find some way to do it

public abstract class GenericReader
{
protected GenericReader() { }
public abstract int PeekInt();
public abstract string ReadString();
public abstract DateTime ReadDateTime();
public abstract DateTimeOffset ReadDateTimeOffset();
public abstract TimeSpan ReadTimeSpan();
public abstract DateTime ReadDeltaTime();
public abstract decimal ReadDecimal();
public abstract long ReadLong();
public abstract ulong ReadULong();
public abstract int ReadInt();
public abstract uint ReadUInt();
public abstract short ReadShort();
public abstract ushort ReadUShort();
public abstract double ReadDouble();
public abstract float ReadFloat();
public abstract char ReadChar();
public abstract byte ReadByte();
public abstract sbyte ReadSByte();
public abstract bool ReadBool();
public abstract int ReadEncodedInt();
public abstract IPAddress ReadIPAddress();
public abstract Point3D ReadPoint3D();
public abstract Point2D ReadPoint2D();
public abstract Rectangle2D ReadRect2D();
public abstract Rectangle3D ReadRect3D();
public abstract Map ReadMap();
public abstract Item ReadItem();
public abstract Mobile ReadMobile();
public abstract BaseGuild ReadGuild();
 
You can always implenent it yourself :D
you know i wish i could! perhaps merge it from servuo and cross my fingers?

I see readobjecttype in servuo... hmm...
so servuo appears to serialize a hash of the object, then use
var hash = ReadEncodedInt();
return ScriptCompiler.FindTypeByFullNameHash(hash);
to get the object type... would this work for a mobile?
 
Last edited:
public abstract int ReadEncodedInt();

At a low level ObjectType uses the EncodedInt() in ServUO which also appears in RunUO, so you should be able to use this information to add it to your project!
Code:
        public override void WriteObjectType(object value)
        {
            WriteObjectType(value?.GetType());
        }

        public override void WriteObjectType(Type value)
        {
            var hash = ScriptCompiler.FindHashByFullName(value?.FullName);

            WriteEncodedInt(hash);
        }

Code:
        public override Type ReadObjectType()
        {
            var hash = ReadEncodedInt();

            return ScriptCompiler.FindTypeByFullNameHash(hash);
        }
 
public abstract int ReadEncodedInt();

At a low level ObjectType uses the EncodedInt() in ServUO which also appears in RunUO, so you should be able to use this information to add it to your project!
Code:
        public override void WriteObjectType(object value)
        {
            WriteObjectType(value?.GetType());
        }

        public override void WriteObjectType(Type value)
        {
            var hash = ScriptCompiler.FindHashByFullName(value?.FullName);

            WriteEncodedInt(hash);
        }

Code:
        public override Type ReadObjectType()
        {
            var hash = ReadEncodedInt();

            return ScriptCompiler.FindTypeByFullNameHash(hash);
        }
much karma to you, friend!
Fixed, without adding code to core!

Turns out runuo does this slightly differently, by seralizing Type.FullName as string, and getting the type from that.

e.g.
public override void Serialize( GenericWriter writer )
{
base.Serialize( writer );
writer.Write( (int) 0 ); // version
string tryingthis = m_mob.FullName.ToString();
writer.Write( tryingthis );
}
public override void Deserialize( GenericReader reader )
{
base.Deserialize( reader );
int version = reader.ReadInt();
m_mob = ScriptCompiler.FindTypeByFullName( reader.ReadString());
}
 
Last edited:
The complexity of serializing a hash for the type is to reduce the amount of data written; a 4-byte integer is much less data to manage as opposed to a variable-length, length-prefixed string.
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back