diff --git a/IllusionPlugin/IEnhancedPlugin.cs b/IllusionPlugin/IEnhancedPlugin.cs new file mode 100644 index 00000000..a3ed3f75 --- /dev/null +++ b/IllusionPlugin/IEnhancedPlugin.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace IllusionPlugin +{ + public interface IEnhancedPlugin : IPlugin + { + /// + /// Gets a list of executables this plugin should be excuted on (without the file ending) + /// + /// { "PlayClub", "PlayClubStudio" } + string[] Filter { get; } + + void OnLateUpdate(); + } +} diff --git a/IllusionPlugin/IPlugin.cs b/IllusionPlugin/IPlugin.cs new file mode 100644 index 00000000..14223a24 --- /dev/null +++ b/IllusionPlugin/IPlugin.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace IllusionPlugin +{ + /// + /// Interface for generic Illusion unity plugins. Every class that implements this will be loaded if the DLL is placed at + /// data/Managed/Plugins. + /// + public interface IPlugin + { + + /// + /// Gets the name of the plugin. + /// + string Name { get; } + + /// + /// Gets the version of the plugin. + /// + string Version { get; } + + /// + /// Gets invoked when the application is started. + /// + void OnApplicationStart(); + + /// + /// Gets invoked when the application is closed. + /// + void OnApplicationQuit(); + + /// + /// Gets invoked whenever a level is loaded. + /// + /// + void OnLevelWasLoaded(int level); + + /// + /// Gets invoked after the first update cycle after a level was loaded. + /// + /// + void OnLevelWasInitialized(int level); + + /// + /// Gets invoked on every graphic update. + /// + void OnUpdate(); + + + /// + /// Gets invoked on ever physics update. + /// + void OnFixedUpdate(); + } +} diff --git a/IllusionPlugin/IllusionPlugin.XML b/IllusionPlugin/IllusionPlugin.XML new file mode 100644 index 00000000..493113b0 --- /dev/null +++ b/IllusionPlugin/IllusionPlugin.XML @@ -0,0 +1,178 @@ + + + + IllusionPlugin + + + + + Gets a list of executables this plugin should be excuted on (without the file ending) + + { "PlayClub", "PlayClubStudio" } + + + + Create a New INI file to store or load data + + + + + INIFile Constructor. + + + + + + Write Data to the INI File + + + Section name + + Key Name + + Value Name + + + + Read Data Value From the Ini File + + + + + + + + + Interface for generic Illusion unity plugins. Every class that implements this will be loaded if the DLL is placed at + data/Managed/Plugins. + + + + + Gets the name of the plugin. + + + + + Gets the version of the plugin. + + + + + Gets invoked when the application is started. + + + + + Gets invoked when the application is closed. + + + + + Gets invoked whenever a level is loaded. + + + + + + Gets invoked after the first update cycle after a level was loaded. + + + + + + Gets invoked on every graphic update. + + + + + Gets invoked on ever physics update. + + + + + Allows to get and set preferences for your mod. + + + + + Gets a string from the ini. + + Section of the key. + Name of the key. + Value that should be used when no value is found. + Whether or not the default value should be written if no value is found. + + + + + Gets an int from the ini. + + Section of the key. + Name of the key. + Value that should be used when no value is found. + Whether or not the default value should be written if no value is found. + + + + + Gets a float from the ini. + + Section of the key. + Name of the key. + Value that should be used when no value is found. + Whether or not the default value should be written if no value is found. + + + + + Gets a bool from the ini. + + Section of the key. + Name of the key. + Value that should be used when no value is found. + Whether or not the default value should be written if no value is found. + + + + + Checks whether or not a key exists in the ini. + + Section of the key. + Name of the key. + + + + + Sets a float in the ini. + + Section of the key. + Name of the key. + Value that should be written. + + + + Sets an int in the ini. + + Section of the key. + Name of the key. + Value that should be written. + + + + Sets a string in the ini. + + Section of the key. + Name of the key. + Value that should be written. + + + + Sets a bool in the ini. + + Section of the key. + Name of the key. + Value that should be written. + + + diff --git a/IllusionPlugin/IllusionPlugin.csproj b/IllusionPlugin/IllusionPlugin.csproj new file mode 100644 index 00000000..057d612b --- /dev/null +++ b/IllusionPlugin/IllusionPlugin.csproj @@ -0,0 +1,55 @@ + + + + + Debug + AnyCPU + {E2848BFB-5432-42F4-8AE0-D2EC0CDF2F71} + Library + Properties + IllusionPlugin + IllusionPlugin + v3.5 + 512 + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + none + true + bin\Release\ + TRACE + prompt + 4 + bin\Release\IllusionPlugin.XML + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IllusionPlugin/IniFile.cs b/IllusionPlugin/IniFile.cs new file mode 100644 index 00000000..d773d9b6 --- /dev/null +++ b/IllusionPlugin/IniFile.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; + +namespace IllusionPlugin +{ + /// + /// Create a New INI file to store or load data + /// + internal class IniFile + { + [DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringW", + SetLastError = true, + CharSet = CharSet.Unicode, ExactSpelling = true, + CallingConvention = CallingConvention.StdCall)] + private static extern int GetPrivateProfileString( + string lpSection, + string lpKey, + string lpDefault, + StringBuilder lpReturnString, + int nSize, + string lpFileName); + + [DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringW", + SetLastError = true, + CharSet = CharSet.Unicode, ExactSpelling = true, + CallingConvention = CallingConvention.StdCall)] + private static extern int WritePrivateProfileString( + string lpSection, + string lpKey, + string lpValue, + string lpFileName); + + private string _path = ""; + public string Path + { + get + { + return _path; + } + set + { + if (!File.Exists(value)) + File.WriteAllText(value, "", Encoding.Unicode); + _path = value; + } + } + + /// + /// INIFile Constructor. + /// + /// + public IniFile(string INIPath) + { + this.Path = INIPath; + } + + /// + /// Write Data to the INI File + /// + /// + /// Section name + /// + /// Key Name + /// + /// Value Name + public void IniWriteValue(string Section, string Key, string Value) + { + WritePrivateProfileString(Section, Key, Value, this.Path); + } + + /// + /// Read Data Value From the Ini File + /// + /// + /// + /// + /// + public string IniReadValue(string Section, string Key) + { + const int MAX_CHARS = 1023; + StringBuilder result = new StringBuilder(MAX_CHARS); + GetPrivateProfileString(Section, Key, "", result, MAX_CHARS, this.Path); + return result.ToString(); + } + } +} diff --git a/IllusionPlugin/ModPrefs.cs b/IllusionPlugin/ModPrefs.cs new file mode 100644 index 00000000..9c55d37c --- /dev/null +++ b/IllusionPlugin/ModPrefs.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace IllusionPlugin +{ + /// + /// Allows to get and set preferences for your mod. + /// + public static class ModPrefs + { + private static IniFile _instance; + private static IniFile Instance + { + get + { + if (_instance == null) + { + _instance = new IniFile(Path.Combine(Environment.CurrentDirectory, "UserData/modprefs.ini")); + } + return _instance; + } + } + + + /// + /// Gets a string from the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be used when no value is found. + /// Whether or not the default value should be written if no value is found. + /// + public static string GetString(string section, string name, string defaultValue = "", bool autoSave = false) + { + string value = Instance.IniReadValue(section, name); + if (value != "") + return value; + else if (autoSave) + SetString(section, name, defaultValue); + + return defaultValue; + } + + /// + /// Gets an int from the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be used when no value is found. + /// Whether or not the default value should be written if no value is found. + /// + public static int GetInt(string section, string name, int defaultValue = 0, bool autoSave = false) + { + int value; + if (int.TryParse(Instance.IniReadValue(section, name), out value)) + return value; + else if (autoSave) + SetInt(section, name, defaultValue); + + return defaultValue; + } + + + /// + /// Gets a float from the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be used when no value is found. + /// Whether or not the default value should be written if no value is found. + /// + public static float GetFloat(string section, string name, float defaultValue = 0f, bool autoSave = false) + { + float value; + if (float.TryParse(Instance.IniReadValue(section, name), out value)) + return value; + else if (autoSave) + SetFloat(section, name, defaultValue); + + return defaultValue; + } + + /// + /// Gets a bool from the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be used when no value is found. + /// Whether or not the default value should be written if no value is found. + /// + public static bool GetBool(string section, string name, bool defaultValue = false, bool autoSave = false) + { + string sVal = GetString(section, name, null); + if (sVal == "1" || sVal == "0") + { + return sVal == "1"; + } else if (autoSave) + { + SetBool(section, name, defaultValue); + } + + return defaultValue; + } + + + /// + /// Checks whether or not a key exists in the ini. + /// + /// Section of the key. + /// Name of the key. + /// + public static bool HasKey(string section, string name) + { + return Instance.IniReadValue(section, name) != null; + } + + /// + /// Sets a float in the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be written. + public static void SetFloat(string section, string name, float value) + { + Instance.IniWriteValue(section, name, value.ToString()); + } + + /// + /// Sets an int in the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be written. + public static void SetInt(string section, string name, int value) + { + Instance.IniWriteValue(section, name, value.ToString()); + + } + + /// + /// Sets a string in the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be written. + public static void SetString(string section, string name, string value) + { + Instance.IniWriteValue(section, name, value); + + } + + /// + /// Sets a bool in the ini. + /// + /// Section of the key. + /// Name of the key. + /// Value that should be written. + public static void SetBool(string section, string name, bool value) + { + Instance.IniWriteValue(section, name, value ? "1" : "0"); + + } + } +} diff --git a/IllusionPlugin/Properties/AssemblyInfo.cs b/IllusionPlugin/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..3380ee3e --- /dev/null +++ b/IllusionPlugin/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("IllusionPlugin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IllusionPlugin")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e8cea89d-6c2f-4729-94b3-f355f7db19e5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache b/IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache new file mode 100644 index 00000000..a3afe4a3 --- /dev/null +++ b/IllusionPlugin/obj/Debug/IllusionPlugin.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +dd098bdf8443f9e98a9261f325ce0c78fe53aba4