Allowed for custom types to be added in how to process a class multiple ways. Also added support for SDV.HUDMessages
This commit is contained in:
parent
b3a9cb7b0a
commit
20f52e2707
|
@ -3,6 +3,7 @@ using ModdedUtilitiesNetworking.Framework;
|
||||||
using ModdedUtilitiesNetworking.Framework.Clients;
|
using ModdedUtilitiesNetworking.Framework.Clients;
|
||||||
using ModdedUtilitiesNetworking.Framework.Delegates;
|
using ModdedUtilitiesNetworking.Framework.Delegates;
|
||||||
using ModdedUtilitiesNetworking.Framework.Extentions;
|
using ModdedUtilitiesNetworking.Framework.Extentions;
|
||||||
|
using ModdedUtilitiesNetworking.Framework.Extentions.StrardewValleyExtentions;
|
||||||
using ModdedUtilitiesNetworking.Framework.Servers;
|
using ModdedUtilitiesNetworking.Framework.Servers;
|
||||||
using StardewModdingAPI;
|
using StardewModdingAPI;
|
||||||
using StardewValley;
|
using StardewValley;
|
||||||
|
@ -15,10 +16,25 @@ using System.Reflection;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ModdedUtilitiesNetworking.Framework.Features;
|
||||||
using static ModdedUtilitiesNetworking.Framework.Delegates.DelegateInfo;
|
using static ModdedUtilitiesNetworking.Framework.Delegates.DelegateInfo;
|
||||||
|
|
||||||
namespace ModdedUtilitiesNetworking
|
namespace ModdedUtilitiesNetworking
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
*When adding a new supported type...
|
||||||
|
* 1.Make reader and writer overload functions
|
||||||
|
* 2.Add supported type to objectTypes list using addObjectType or addCustomObjectType
|
||||||
|
*
|
||||||
|
* When adding a new supported function...
|
||||||
|
* 1.Make sure the supported type is handled first!
|
||||||
|
* 2.Add in a function that will accept the object data and parse the data to do what you want.
|
||||||
|
* 3. Add funtion to possibleVoidFunctions
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* TODO:
|
||||||
|
* Make CustomGalaxyClient work.
|
||||||
|
*/
|
||||||
public class ModCore : Mod
|
public class ModCore : Mod
|
||||||
{
|
{
|
||||||
public static CustomMultiplayer multiplayer;
|
public static CustomMultiplayer multiplayer;
|
||||||
|
@ -45,6 +61,7 @@ namespace ModdedUtilitiesNetworking
|
||||||
multiplayer = new CustomMultiplayer();
|
multiplayer = new CustomMultiplayer();
|
||||||
|
|
||||||
possibleVoidFunctions.Add(displayMessageString, new voidFunc(displayMessage));
|
possibleVoidFunctions.Add(displayMessageString, new voidFunc(displayMessage));
|
||||||
|
possibleVoidFunctions.Add(Framework.Features.Stardew.MessageFeatures.FSTRING_SendHUDMessageWithIcon, Framework.Features.Stardew.MessageFeatures.SendHUDMessageWithIcon);
|
||||||
initializeBasicTypes();
|
initializeBasicTypes();
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +73,7 @@ namespace ModdedUtilitiesNetworking
|
||||||
|
|
||||||
if (e.KeyPressed==Microsoft.Xna.Framework.Input.Keys.K)
|
if (e.KeyPressed==Microsoft.Xna.Framework.Input.Keys.K)
|
||||||
{
|
{
|
||||||
multiplayer.sendModInfoReturnVoid(displayMessageString, typeof(String), (object)"My love is like fire.");
|
multiplayer.sendModInfoReturnVoid(Framework.Features.Stardew.MessageFeatures.FSTRING_SendHUDMessageWithIcon, MessagesExtentions.HUDMessageIconIdentifier, new HUDMessage("My love is like fire",1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,6 +175,7 @@ namespace ModdedUtilitiesNetworking
|
||||||
addObjectType(monitor,typeof(List<String>), new ReadWriter(new reader(GenericExtentions.ReadStringList), new writer(GenericExtentions.WriteStringList)));
|
addObjectType(monitor,typeof(List<String>), new ReadWriter(new reader(GenericExtentions.ReadStringList), new writer(GenericExtentions.WriteStringList)));
|
||||||
addObjectType(monitor, typeof(DataInfo), new ReadWriter(new reader(GenericExtentions.ReadDataInfo), new writer(GenericExtentions.WriteDataInfo)));
|
addObjectType(monitor, typeof(DataInfo), new ReadWriter(new reader(GenericExtentions.ReadDataInfo), new writer(GenericExtentions.WriteDataInfo)));
|
||||||
|
|
||||||
|
addObjectCustomType(monitor, MessagesExtentions.HUDMessageIconIdentifier, new ReadWriter(new reader(MessagesExtentions.ReadHUDMessageWithIcon), new writer(MessagesExtentions.WriteHUDMessageWithIcon)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -179,6 +197,25 @@ namespace ModdedUtilitiesNetworking
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds "types" using a string convention to be able to allow processing of the same class type in different ways.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="monitor"></param>
|
||||||
|
/// <param name="t"></param>
|
||||||
|
/// <param name="readWriter"></param>
|
||||||
|
public static void addObjectCustomType(IMonitor monitor, string t, ReadWriter readWriter)
|
||||||
|
{
|
||||||
|
if (objectTypes.ContainsKey(t.ToString()) == false)
|
||||||
|
{
|
||||||
|
objectTypes.Add(t, readWriter);
|
||||||
|
monitor.Log("Added custom supported type: " + t.ToString() + " to ModdedUtilitiesNetworking.", LogLevel.Info);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
monitor.Log("Error custom adding supported type: " + t.ToString() + " to ModdedUtilitiesNetworking. Type already supported!", LogLevel.Alert);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Process all possible functions that can occur.
|
/// Process all possible functions that can occur.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -77,7 +77,7 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a net outgoing message that is written specifically to call a void function when sent.
|
/// Creates a net outgoing message that is written specifically to call a void function when sent. USed to specifiy types and specific ways to handle them.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="functionName"></param>
|
/// <param name="functionName"></param>
|
||||||
/// <param name="objectParametersType"></param>
|
/// <param name="objectParametersType"></param>
|
||||||
|
@ -125,5 +125,21 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
ModCore.multiplayer.sendMessage(message);
|
ModCore.multiplayer.sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates all of the necessary parameters for the outgoing message to be sent to the server/client on what to do and how to handle the data sent.
|
||||||
|
/// This message written will attempt to access a function that doesn't return anything. Essentially null.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uniqueID"></param>
|
||||||
|
/// <param name="classType"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
public void sendModInfoReturnVoid(string uniqueID, string classType, object data)
|
||||||
|
{
|
||||||
|
Farmer f = Game1.player;
|
||||||
|
|
||||||
|
OutgoingMessage message = ModCore.multiplayer.sendOutGoingMessageReturnVoid(uniqueID, classType, data, f);
|
||||||
|
|
||||||
|
ModCore.multiplayer.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,90 +21,6 @@ namespace ModdedUtilitiesNetworking.Framework
|
||||||
this.data = Data;
|
this.data = Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeCode GetTypeCode()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ToBoolean(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte ToByte(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public char ToChar(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DateTime ToDateTime(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public decimal ToDecimal(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public double ToDouble(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public short ToInt16(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ToInt32(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long ToInt64(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public sbyte ToSByte(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public float ToSingle(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public string ToString(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
return this.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public object ToType(Type conversionType, IFormatProvider provider)
|
|
||||||
{
|
|
||||||
return this.GetType();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ushort ToUInt16(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
ushort ushortValue1 = 53612;
|
|
||||||
return ushortValue1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public uint ToUInt32(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ulong ToUInt64(IFormatProvider provider)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
using StardewValley;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ModdedUtilitiesNetworking.Framework.Extentions.StrardewValleyExtentions
|
||||||
|
{
|
||||||
|
public static class MessagesExtentions
|
||||||
|
{
|
||||||
|
|
||||||
|
public static string HUDMessageIconIdentifier= typeof(HUDMessage).ToString()+".MessageWithIcon";
|
||||||
|
|
||||||
|
public static HUDMessage ReadHUDMessageWithIcon(this BinaryReader reader)
|
||||||
|
{
|
||||||
|
string message = reader.ReadString();
|
||||||
|
int messageType = reader.ReadInt32();
|
||||||
|
|
||||||
|
return new HUDMessage(message,messageType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void WriteHUDMessageWithIcon(this BinaryWriter writer, object obj)
|
||||||
|
{
|
||||||
|
HUDMessage message =(HUDMessage) obj;
|
||||||
|
writer.WriteString(message.message);
|
||||||
|
writer.Write(message.whatType);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
using StardewValley;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ModdedUtilitiesNetworking.Framework.Features.Stardew
|
||||||
|
{
|
||||||
|
public class MessageFeatures
|
||||||
|
{
|
||||||
|
|
||||||
|
public static string FSTRING_SendHUDMessageWithIcon = "Omegasis.ModdedUtilitiesNetworking.Framework.Features.Stardew.MessageFeatures.SendHUDMessageWithIcon";
|
||||||
|
|
||||||
|
public static string FSTRING_DisplayConsoleMessageString = "Omegasis.ModdedUtilitiesNetworking.Framework.Features.Stardew.MessageFeatures.DisplayConsoleMessage";
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Displays a HUD message to all clients and server containing this information.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
public static void SendHUDMessageWithIcon(object data)
|
||||||
|
{
|
||||||
|
DataInfo obj = (DataInfo)data;
|
||||||
|
string type = obj.type;
|
||||||
|
HUDMessage message =(HUDMessage)obj.data;
|
||||||
|
Game1.addHUDMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Static Debug function.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="param"></param>
|
||||||
|
public static void DisplayConsoleMessage(object param)
|
||||||
|
{
|
||||||
|
DataInfo dataInfo = (DataInfo)param;
|
||||||
|
string s = (string)dataInfo.data;
|
||||||
|
ModCore.monitor.Log(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -197,8 +197,14 @@ namespace ModdedUtilitiesNetworking.Framework.Servers
|
||||||
using (NetBufferWriteStream bufferWriteStream = new NetBufferWriteStream((NetBuffer)message1))
|
using (NetBufferWriteStream bufferWriteStream = new NetBufferWriteStream((NetBuffer)message1))
|
||||||
{
|
{
|
||||||
using (BinaryWriter writer = new BinaryWriter((Stream)bufferWriteStream)) {
|
using (BinaryWriter writer = new BinaryWriter((Stream)bufferWriteStream)) {
|
||||||
|
if (message.MessageType != 20)
|
||||||
|
{
|
||||||
message.Write(writer);
|
message.Write(writer);
|
||||||
//OutgoingMessageBase.WriteFromMessage(message, writer);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OutgoingMessageBase.WriteFromMessage(message, writer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int num = (int)this.server.SendMessage(message1, connection, NetDeliveryMethod.ReliableOrdered);
|
int num = (int)this.server.SendMessage(message1, connection, NetDeliveryMethod.ReliableOrdered);
|
||||||
|
|
|
@ -55,7 +55,9 @@
|
||||||
<Compile Include="Framework\DataInfo.cs" />
|
<Compile Include="Framework\DataInfo.cs" />
|
||||||
<Compile Include="Framework\Delegates\DelegateInfo.cs" />
|
<Compile Include="Framework\Delegates\DelegateInfo.cs" />
|
||||||
<Compile Include="Framework\Extentions\GenericExtentions.cs" />
|
<Compile Include="Framework\Extentions\GenericExtentions.cs" />
|
||||||
|
<Compile Include="Framework\Extentions\StrardewValleyExtentions\MessagesExtentions.cs" />
|
||||||
<Compile Include="Framework\Extentions\XNAExtentions.cs" />
|
<Compile Include="Framework\Extentions\XNAExtentions.cs" />
|
||||||
|
<Compile Include="Framework\Features\Stardew\MessageFeatures.cs" />
|
||||||
<Compile Include="Framework\Messages\OutgoingMessageBase.cs" />
|
<Compile Include="Framework\Messages\OutgoingMessageBase.cs" />
|
||||||
<Compile Include="Framework\CustomMultiplayer.cs" />
|
<Compile Include="Framework\CustomMultiplayer.cs" />
|
||||||
<Compile Include="Framework\Network\NetBufferReadStream.cs" />
|
<Compile Include="Framework\Network\NetBufferReadStream.cs" />
|
||||||
|
|
Loading…
Reference in New Issue