Ver Fonte

Added a plugin to append extra data to cards

Bepis há 6 anos atrás
pai
commit
bf235c9659

+ 8 - 1
BepInEx.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 15
-VisualStudioVersion = 15.0.27130.2027
+VisualStudioVersion = 15.0.27130.2036
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BepInEx", "BepInEx\BepInEx.csproj", "{4FFBA620-F5ED-47F9-B90C-DAD1316FD9B9}"
 EndProject
@@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ResourceRedirector", "Plugi
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeveloperConsole", "Plugins\DeveloperConsole\DeveloperConsole.csproj", "{434F00D0-BD2A-4C81-A2FE-8DBFBBD9D9AB}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExtensibleSaveFormat", "Plugins\ExtensibleSaveFormat\ExtensibleSaveFormat.csproj", "{8EBE81B9-9ED9-466D-864A-4C644BFD8827}"
+EndProject
 Global
 	GlobalSection(SharedMSBuildProjectFiles) = preSolution
 		BepInEx.Common\BepInEx.Common.projitems*{4ffba620-f5ed-47f9-b90c-dad1316fd9b9}*SharedItemsImports = 4
@@ -72,6 +74,10 @@ Global
 		{434F00D0-BD2A-4C81-A2FE-8DBFBBD9D9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{434F00D0-BD2A-4C81-A2FE-8DBFBBD9D9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{434F00D0-BD2A-4C81-A2FE-8DBFBBD9D9AB}.Release|Any CPU.Build.0 = Release|Any CPU
+		{8EBE81B9-9ED9-466D-864A-4C644BFD8827}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{8EBE81B9-9ED9-466D-864A-4C644BFD8827}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{8EBE81B9-9ED9-466D-864A-4C644BFD8827}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{8EBE81B9-9ED9-466D-864A-4C644BFD8827}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -84,6 +90,7 @@ Global
 		{6A9D08C0-4482-4D1A-9368-9F41B7126F9E} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
 		{3EA76CA3-45B6-4A1A-B04F-7A1A8C978AF6} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
 		{434F00D0-BD2A-4C81-A2FE-8DBFBBD9D9AB} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
+		{8EBE81B9-9ED9-466D-864A-4C644BFD8827} = {FF8CE2C8-C185-4EA9-8D63-E2542F0C2FCF}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {55AC11EF-F568-4C79-A356-7ED9510145B1}

+ 36 - 0
Plugins/ExtensibleSaveFormat/ExtensibleSaveFormat.cs

@@ -0,0 +1,36 @@
+using BepInEx;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace ExtensibleSaveFormat
+{
+    public class ExtensibleSaveFormat : BaseUnityPlugin
+    {
+        public override string ID => "extendedsave";
+
+        public override string Name => "Extensible Save Format";
+
+        public override Version Version => new Version("1.0");
+
+
+        internal static Dictionary<ChaFile, Dictionary<string, object>> internalDictionary = new Dictionary<ChaFile, Dictionary<string, object>>();
+
+        public ExtensibleSaveFormat()
+        {
+            Hooks.InstallHooks();
+        }
+
+
+        public static bool TryGetExtendedFormat(ChaFile file, out Dictionary<string, object> extendedFormatData)
+        {
+            return internalDictionary.TryGetValue(file, out extendedFormatData);
+        }
+
+        public static void SetExtendedFormat(ChaFile file, Dictionary<string, object> extendedFormatData)
+        {
+            internalDictionary[file] = extendedFormatData;
+        }
+    }
+}

+ 69 - 0
Plugins/ExtensibleSaveFormat/ExtensibleSaveFormat.csproj

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{8EBE81B9-9ED9-466D-864A-4C644BFD8827}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>ExtensibleSaveFormat</RootNamespace>
+    <AssemblyName>ExtensibleSaveFormat</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>K:\BepInEx\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>K:\BepInEx\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="0Harmony">
+      <HintPath>..\..\lib\0Harmony.dll</HintPath>
+      <Private>False</Private>
+    </Reference>
+    <Reference Include="Assembly-CSharp">
+      <HintPath>..\..\lib\Assembly-CSharp.dll</HintPath>
+      <Private>False</Private>
+    </Reference>
+    <Reference Include="Assembly-CSharp-firstpass">
+      <HintPath>..\..\lib\Assembly-CSharp-firstpass.dll</HintPath>
+      <Private>False</Private>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+    <Reference Include="UnityEngine">
+      <HintPath>..\..\lib\UnityEngine.dll</HintPath>
+      <Private>False</Private>
+    </Reference>
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="ExtensibleSaveFormat.cs" />
+    <Compile Include="Hooks.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\BepInEx\BepInEx.csproj">
+      <Project>{4ffba620-f5ed-47f9-b90c-dad1316fd9b9}</Project>
+      <Name>BepInEx</Name>
+      <Private>False</Private>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>

+ 71 - 0
Plugins/ExtensibleSaveFormat/Hooks.cs

@@ -0,0 +1,71 @@
+using Harmony;
+using MessagePack;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+
+namespace ExtensibleSaveFormat
+{
+    public static class Hooks
+    {
+        public static void InstallHooks()
+        {
+            var harmony = HarmonyInstance.Create("com.bepis.bepinex.extensiblesaveformat");
+
+
+            MethodInfo original = AccessTools.Method(typeof(ChaFile), "SaveFile", new[] { typeof(BinaryWriter), typeof(bool) });
+
+            HarmonyMethod postfix = new HarmonyMethod(typeof(Hooks).GetMethod("SaveFileHook"));
+
+            harmony.Patch(original, null, postfix);
+
+
+            original = AccessTools.Method(typeof(ChaFile), "LoadFile", new[] { typeof(BinaryReader), typeof(bool), typeof(bool) });
+
+            postfix = new HarmonyMethod(typeof(Hooks).GetMethod("LoadFileHook"));
+
+            harmony.Patch(original, null, postfix);
+        }
+
+        public static void SaveFileHook(ChaFile __instance, bool __result, BinaryWriter bw, bool savePng)
+        {
+            if (!__result)
+                return;
+
+            if (!ExtensibleSaveFormat.TryGetExtendedFormat(__instance, out Dictionary<string, object> extendedData))
+                return;
+
+            byte[] bytes = MessagePackSerializer.Serialize(extendedData);
+
+            bw.Write((int)bytes.Length);
+            bw.Write(bytes);
+        }
+
+        public static void LoadFileHook(ChaFile __instance, bool __result, BinaryReader br, bool noLoadPNG, bool noLoadStatus)
+        {
+            if (!__result)
+                return;
+
+            try
+            {
+                int length = br.ReadInt32();
+
+                if (length > 0)
+                {
+                    byte[] bytes = br.ReadBytes(length);
+
+                    ExtensibleSaveFormat.internalDictionary[__instance] = MessagePackSerializer.Deserialize<Dictionary<string, object>>(bytes);
+
+                    return;
+                }
+            }
+            catch (EndOfStreamException) { }
+
+            //initialize a new dictionary since it doesn't exist
+            ExtensibleSaveFormat.internalDictionary[__instance] = new Dictionary<string, object>();
+        }
+    }
+}

+ 36 - 0
Plugins/ExtensibleSaveFormat/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("ExtensibleSaveFormat")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ExtensibleSaveFormat")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[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("8ebe81b9-9ed9-466d-864a-4c644bfd8827")]
+
+// 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")]