Base System Files. Missing 2 Module Scripts.
This commit is contained in:
Unstable Kitsune
2023-12-09 22:51:45 -05:00
parent 487f90ea32
commit 9cfde37097
7 changed files with 612 additions and 1 deletions

View File

@@ -0,0 +1,204 @@
using System;
using System.IO;
using System.Collections.Generic;
using Server;
namespace KCS
{
public partial class KCS
{
public static void Initialize()
{
EventSink.WorldSave += new WorldSaveEventHandler(Save);
Load();
}
private static Dictionary<string, bool> mRegSyst = new Dictionary<string, bool>();
public static Dictionary<string, bool> RegisteredSystem { get { return mRegSyst; } }
public static void RegisterSystem(string system)
{
if (mRegSyst.ContainsKey(system))
return;
Type type = Type.GetType(system);
if (type == null)
{
Console.WriteLine("Unauthorized Addon Detected: " + system);
return;
}
KCSSystem mSyst = (KCSSystem)Activator.CreateInstance(type);
if (mSyst != null)
{
mRegSyst.Add(system, true);
Console.WriteLine("Kitsunic System Registered:" + system);
}
}
public static bool SystEnabled(string system)
{
return mRegSyst.ContainsKey(system) && (bool)mRegSyst[system];
}
public static void SystDisabled(string system)
{
if (mRegSyst.ContainsKey(system))
{
Type type = ScriptCompiler.FindTypeByFullName(system);
if (type != null)
{
if (!Directory.Exists("Kitsunic"))
Directory.CreateDirectory("Kitsunic");
KCSSystem Syst = (KCSSystem)Activator.CreateInstance(type);
if (Syst != null)
{
Syst.StartSave("Kitsunic/");
Syst.Disable();
}
mRegSyst[system] = false;
}
}
else
Console.WriteLine("Unauthorized System - {0} - Disabling is Impossible" + system);
}
public static void EnableSystem(string system)
{
if (mRegSyst.ContainsKey(system))
{
Type type = ScriptCompiler.FindTypeByFullName(system);
if (type != null)
{
if (!Directory.Exists("Kitsunic"))
Directory.CreateDirectory("Kitsunic");
KCSSystem Syst = (KCSSystem)Activator.CreateInstance(type);
if (Syst != null)
{
Syst.StartLoad("Kitsunic/");
Syst.Enable();
}
mRegSyst[system] = true;
}
}
else
Console.WriteLine("Unauthorized System - {0} - Enabling is Impossible" + system);
}
public static void Save(WorldSaveEventArgs mArgs)
{
if (!Directory.Exists("Saves/Kitsunic"))
Directory.CreateDirectory("Saves/Kitsunic");
string filename = "Kitsunic.sav";
string path = @"Saves/Kitsunic/";
string pfilename = path + filename;
DateTime start = DateTime.Now;
Console.WriteLine();
Console.WriteLine();
Console.WriteLine(". . . . . . . . .");
Console.WriteLine("Brewing Kitsunic Potions. . .");
try
{
using (FileStream mFileStream = new FileStream(pfilename, FileMode.OpenOrCreate, FileAccess.Write))
{
BinaryFileWriter writer = new BinaryFileWriter(mFileStream, true);
writer.Write((int)mRegSyst.Count);
foreach ( KeyValuePair<string,bool> keyValuePair in mRegSyst )
{
Type type = ScriptCompiler.FindTypeByFullName(keyValuePair.Key);
if(type != null)
{
writer.Write(keyValuePair.Key);
writer.Write(keyValuePair.Value);
if(keyValuePair.Value)
{
KCSSystem system = (KCSSystem)Activator.CreateInstance(type);
if (system != null)
system.StartSave(path);
}
}
}
writer.Close();
mFileStream.Close();
}
Console.WriteLine("Completing in {0:F1} Seconds.", (DateTime.Now - start).TotalSeconds);
Console.WriteLine(". . . . . . .");
Console.WriteLine();
}
catch (Exception err)
{
Console.WriteLine("Saving Failed. Reason:" + err);
}
}
public static void Load()
{
if (!Directory.Exists("Saves/Kitsunic"))
return;
string filename = "Kitsunic.sav";
string path = @"Saves/Kitsunic/";
string pfilename = path + filename;
DateTime start = DateTime.Now;
Console.WriteLine();
Console.WriteLine(". . . . . . . . .");
Console.WriteLine("Brewing Kitsunic Toxins. . .");
try
{
using (FileStream mFileStream = new FileStream(pfilename, FileMode.Open, FileAccess.Read))
{
BinaryReader mBinaryReader = new BinaryReader(mFileStream);
BinaryFileReader reader = new BinaryFileReader(mBinaryReader);
if (mRegSyst == null)
mRegSyst = new Dictionary<string, bool>();
int Count = reader.ReadInt();
for(int i = 0; i < Count; i++)
{
string system = reader.ReadString();
Type type = ScriptCompiler.FindTypeByFullName(system);
bool enabled = reader.ReadBool();
if( type != null )
{
mRegSyst[system] = enabled;
if (mRegSyst[system])
{
KCSSystem mSyst = (KCSSystem)Activator.CreateInstance(type);
if (mSyst != null)
mSyst.StartLoad(path);
}
}
}
reader.Close();
mFileStream.Close();
}
Console.WriteLine("Completed in {0:F1} seconds.", (DateTime.Now - start).TotalSeconds);
Console.WriteLine(". . . . . . . . .");
Console.WriteLine();
}
catch(Exception err )
{
Console.WriteLine("Loading Failed. Reason:" + err);
}
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace KCS
{
public class KCSParams
{
public KCSParams()
{
}
}
}

View File

@@ -0,0 +1,96 @@
using System;
using System.IO;
using Server;
using Server.Gumps;
using Server.Network;
namespace KCS
{
public abstract class KCSSystem
{
public abstract string Name();
public abstract void Enable();
public abstract void Disable();
public abstract void Save(GenericWriter kcs, GenericWriter kitsunic, GenericWriter writer);
public abstract void Load(BinaryReader kcs, BinaryReader kitsunic, BinaryReader reader);
public abstract void Gump(Mobile from, Gump gump, KCSParams subParams);
public abstract void Help(Mobile from, Gump gump);
public abstract void OnResponse(NetState state, RelayInfo info, KCSParams subParams);
public bool Enabled { get { return KCS.SystEnabled(this.ToString()); } }
public void StartSave(string path)
{
path += Name() + "/";
if(!Directory.Exists(path))
Directory.CreateDirectory(path);
try
{
GenericWriter kcs = new BinaryFileWriter(path + Name() + ".kcs", false);
GenericWriter kitsunic = new BinaryFileWriter(path + Name() + ".sunic", false);
GenericWriter bin = new BinaryFileWriter(path + Name() + ".bin", true);
Console.Write("Brewing {0}...", Name());
Save(kcs, kitsunic, bin);
kcs.Close();
kitsunic.Close();
bin.Close();
Console.WriteLine("Brewing Complete");
}
catch(Exception exception)
{
Console.WriteLine(exception.Message);
}
}//StartSave
public void StartLoad(string path)
{
path += Name() + "/";
string kcsPath = path + Name() + ".kcs";
string kitsunicPath = path + Name() + ".kitsunic";
string binPath = path + Name() + ".bin";
if(!Directory.Exists(path))
Directory.CreateDirectory(path);
if(File.Exists(kcsPath)&&File.Exists(kitsunicPath)&&File.Exists(binPath))
{
using (FileStream kcs = new FileStream(kcsPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using(FileStream kitsunic = new FileStream(kitsunicPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using(FileStream bin = new FileStream(binPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
BinaryReader binReader = new BinaryReader(bin);
BinaryReader kitsunicReader = new BinaryReader(kitsunic);
BinaryReader kcsReader = new BinaryReader(kcs);
Console.Write("Pouring {0}", Name());
Load(kcsReader, kitsunicReader, binReader);
kcsReader.Close();
kitsunicReader.Close();
binReader.Close();
kcs.Close();
kitsunic.Close();
bin.Close();
Console.WriteLine("Pouring Complete");
}//bin
}//kitsunic
}//kcs
}//threePaths
}//StartLoad
}//KCSSystem
} //KCS

View File

@@ -0,0 +1,136 @@
using System;
using System.Collections.Generic;
using Server;
using Server.Commands;
using Server.Gumps;
using Server.Network;
namespace KCS
{
public class KCSGump : Gump
{
public static void Initialize()
{
CommandSystem.Register("KCS", Permissions.GlobalAccessLevel, new CommandEventHandler(OnCommand));
}
[Usage("KSC")]
[Aliases("kcs")]
[Description( "Sends the KCS Gump" )]
private static void OnCommand( CommandEventArgs e )
{
e.Mobile.SendGump(new KCSGump(e.Mobile, null, null));
}
private List<string> mList;
private string mSystString;
private KCSSystem mSyst;
private KCSParams mSubp;
public KCSGump( Mobile from, string system, KCSParams subParams ) : base( 0,0 )
{
if (from.AccessLevel < Permissions.GlobalAccessLevel)
return;
mList = new List<string>();
mSystString = system;
//mSubp = subParams;
foreach (KeyValuePair<string, bool> keyValuePair in KCS.RegisteredSystem)
{
mList.Add( keyValuePair.Key );
}
Closable = true;
Disposable = true;
Dragable = true;
Resizable = true;
AddPage(0);
AddBackground(0, 0, 630, 360, 5120); //Top BackGround
AddBackground(0, 360, 630, 113, 5120); //Bottom Background
AddImageTiled(0, 446, 620, 50, 10452); //Bottom
if( system == null )
{
AddHtml(175, 40, 375, 30, "<basefont size=7 color=#33CC33><center>Kitsunic Custom System </center></basefont>", false, false);
AddHtml(175, 80, 420, 256, "<basefont size=4 color=white>Thank you for Choosing to Test Kitsunic Custom System</basefont>", false, false);
}
for( int i = 0; i < mList.Count; i++ )
{
Type type = Type.GetType(mList[i]);
if (type == null)
continue;
KCSSystem mSystem = (KCSSystem)Activator.CreateInstance ( type );
if ( mSystem == null )
continue;
AddButton(i < 3 ? 35 : (i < 6 ? 255 : 415), (i % 3 == 0 ? 372 : (i % 3 == 1 ? 397 : 442)), 1122, 1124, i + 1, GumpButtonType.Reply, 0);
AddHtml((i < 3 ? 35 : (i < 6 ? 255 : 415)), (i % 3 == 0 ? 370 : (i % 3 == 1 ?395:420)), 184, 20, String.Format("<basefont color=white><center>{0}</center></basefont>", mSystem.Name()), false, false);
if (system != mList[i])
mSyst = mSystem;
}
if( mSyst != null )
{
AddButton(560, 0, 1417, 1417, 10, GumpButtonType.Reply, 0);
if (mSyst.Enabled)
AddLabel(592, 45, 66, "On");
else
AddLabel(588, 45, 36, "Off");
AddButton(15,340,22153,22155,11,GumpButtonType.Reply, 0);
}
AddImage(0, 0, 9002);
AddImage(580, 350, 10410);
if(mSyst != null)
{
AddPage(1);
mSyst.Gump(from, this, subParams);
}
}
public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID == 0 || sender.Mobile.AccessLevel < Permissions.GlobalAccessLevel)
return;
if(info.ButtonID >= 1 && info.ButtonID < 10)
{
int page = info.ButtonID - 1;
if (mSystString == mList[page])
sender.Mobile.SendGump(new KCSGump(sender.Mobile, null, null));
else if(page >= 0 && page <= mList.Count)
sender.Mobile.SendGump(new KCSGump(sender.Mobile, mList[page], null));
return;
}
if(info.ButtonID == 10 && mSyst != null)
{
sender.Mobile.SendMessage("{0} {1}", (mSyst.Enabled ? "Disabling" : "Enabling"), mSyst.Name());
if(mSyst.Enabled)
KCS.SystDisabled(mSyst.ToString() );
else
KCS.EnableSystem(mSyst.ToString() );
sender.Mobile.SendGump(new KCSGump(sender.Mobile, mSystString, mSubp));
return;
}
if(info.ButtonID == 11 && mSyst != null)
{
//mSyst.Help(sender, info);
}
if (mSyst != null)
mSyst.OnResponse(sender, info, mSubp);
}
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Server;
namespace KCS
{
internal class Permissions
{
public static AccessLevel GlobalAccessLevel = AccessLevel.Administrator;
public static AccessLevel SupporterAccessLevel = AccessLevel.VIP;
}
}