Skip to content

Commit

Permalink
ModLoader.PlayHome
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelhauled committed Dec 31, 2019
1 parent 6890630 commit 0d1601c
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 0 deletions.
9 changes: 9 additions & 0 deletions KeelPlugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing.AISyoujyo", "src\Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CameraTargetFix.PlayHome", "src\CameraTargetFix.PlayHome\CameraTargetFix.PlayHome.csproj", "{D77FA629-BC45-4FFA-BDFF-A930089E88F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModLoader.PlayHome", "src\ModLoader.PlayHome\ModLoader.PlayHome.csproj", "{9F4A6B41-3465-4086-A1E2-023699B3F2EE}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\LockOnPlugin.Core\LockOnPlugin.Core.projitems*{073d65ba-9bb7-4386-9b01-f86fa6df6984}*SharedItemsImports = 13
Expand Down Expand Up @@ -159,6 +161,8 @@ Global
src\Common.PlayHome\Common.PlayHome.projitems*{97b9edbf-3152-47db-8240-69818972e177}*SharedItemsImports = 4
src\Common.Core\Common.Core.projitems*{987845c6-3389-4d18-9e1d-43cb0414573e}*SharedItemsImports = 4
src\Common.Koikatu\Common.Koikatu.projitems*{987845c6-3389-4d18-9e1d-43cb0414573e}*SharedItemsImports = 4
src\Common.Core\Common.Core.projitems*{9f4a6b41-3465-4086-a1e2-023699b3f2ee}*SharedItemsImports = 4
src\Common.PlayHome\Common.PlayHome.projitems*{9f4a6b41-3465-4086-a1e2-023699b3f2ee}*SharedItemsImports = 4
src\Common.HoneySelect\Common.HoneySelect.projitems*{a19f5b25-6318-4323-93c8-b27f0343e582}*SharedItemsImports = 13
src\RealPOV.Core\RealPOV.Core.projitems*{a52280cd-3cc4-452a-8c11-67e440e0262f}*SharedItemsImports = 13
src\Common.Core\Common.Core.projitems*{a9a5b556-b590-4948-9e89-87d38623daf1}*SharedItemsImports = 4
Expand Down Expand Up @@ -278,6 +282,10 @@ Global
{D77FA629-BC45-4FFA-BDFF-A930089E88F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D77FA629-BC45-4FFA-BDFF-A930089E88F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D77FA629-BC45-4FFA-BDFF-A930089E88F1}.Release|Any CPU.Build.0 = Release|Any CPU
{9F4A6B41-3465-4086-A1E2-023699B3F2EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9F4A6B41-3465-4086-A1E2-023699B3F2EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F4A6B41-3465-4086-A1E2-023699B3F2EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F4A6B41-3465-4086-A1E2-023699B3F2EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -328,6 +336,7 @@ Global
{0F7D10B7-1180-4537-8804-14545F514C49} = {FF853689-DB4D-4109-9A32-F76A7E85D15B}
{D2625C46-77D9-4D75-BDCD-EA7D402D33F6} = {BA55B5E5-B0FD-465F-93F2-D73BD193AC86}
{D77FA629-BC45-4FFA-BDFF-A930089E88F1} = {FF853689-DB4D-4109-9A32-F76A7E85D15B}
{9F4A6B41-3465-4086-A1E2-023699B3F2EE} = {BA55B5E5-B0FD-465F-93F2-D73BD193AC86}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CECC9C6B-8041-49A1-B7FD-DC89264B7393}
Expand Down
50 changes: 50 additions & 0 deletions src/ModLoader.PlayHome/ModLoader.PlayHome.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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>{9F4A6B41-3465-4086-A1E2-023699B3F2EE}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModLoader.PlayHome</RootNamespace>
<AssemblyName>ModLoader.PlayHome</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<Import Project="..\BuildSettings.PlayHome.props"/>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.BepInEx.Harmony.2.0.0-beta2\lib\net35\0Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.PlayHome.Assembly-CSharp.2018.3.11\lib\net35\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BepInEx, Version=5.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.BepInEx.5.0.1.1\lib\net35\BepInEx.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="BepInEx.Harmony, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.BepInEx.Harmony.2.0.0-beta2\lib\net35\BepInEx.Harmony.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\IllusionLibs.PlayHome.UnityEngine.5.5.5\lib\net35\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ModLoader.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="..\Common.Core\Common.Core.projitems" Label="Shared" />
<Import Project="..\Common.PlayHome\Common.PlayHome.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
164 changes: 164 additions & 0 deletions src/ModLoader.PlayHome/ModLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;

namespace ModLoader.PlayHome
{
[BepInPlugin(GUID, PluginName, Version)]
public class ModLoader : BaseUnityPlugin
{
public const string GUID = "keelhauled.modloader";
public const string PluginName = "ModLoader";
public const string Version = "1.0.0." + BuildNumber.Version;

private static new ManualLogSource Logger;
private Harmony Harmony;

private Type[] types = new[]
{
typeof(PrefabData),
typeof(HairData),
typeof(BackHairData),
typeof(CombineTextureData),
typeof(UnderhairData),
typeof(WearData),
typeof(AccessoryData),
};

private void Awake()
{
Logger = base.Logger;
Harmony = new Harmony($"{GUID}.harmony");

Harmony.Patch(typeof(AssetBundleController).GetMethod("LoadAsset", AccessTools.all).MakeGenericMethod(typeof(Texture2D)),
prefix: new HarmonyMethod(GetType().GetMethod(nameof(LoadAssetPatch), AccessTools.all)));

Harmony.Patch(typeof(ItemDataBase).GetConstructors(AccessTools.all).First(),
prefix: new HarmonyMethod(GetType().GetMethod(nameof(IDPatch), AccessTools.all)));

foreach(var type in types)
{
var targetType = type.Assembly.GetType("CustomDataSetupLoader`1").MakeGenericType(type);
var dicType = typeof(Dictionary<,>).MakeGenericType(typeof(int), type);

Harmony.Patch(targetType.GetMethod("Setup", AccessTools.all),
prefix: new HarmonyMethod(GetType().GetMethod(nameof(SetupPatch), AccessTools.all)));

Harmony.Patch(targetType.GetMethod("Setup_Search", AccessTools.all),
prefix: new HarmonyMethod(GetType().GetMethod(nameof(SetupSearchPrefix), AccessTools.all)),
postfix: new HarmonyMethod(GetType().GetMethod(nameof(SetupSearchPatch), AccessTools.all)));
}
}

private static bool LoadAssetPatch(AssetBundleController __instance, ref string assetName, ref object __result)
{
if(__instance.assetBundleName.Contains("thumnbnail/thumbnail_") || __instance.assetBundleName.Contains("thumnbnail/thumnbs_"))
{
string text = __instance.directory + "/thumnbnail_R/" + assetName + ".png";
if(File.Exists(text))
{
Logger.LogInfo("Load thumb:" + text);
__result = LoadPNG(text);
return false;
}
}

return true;
}

private static Texture2D LoadPNG(string file)
{
byte[] array;

using(var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
using(var binaryReader = new BinaryReader(fileStream))
{
try
{
array = binaryReader.ReadBytes((int)binaryReader.BaseStream.Length);
}
catch(Exception ex)
{
Logger.LogWarning(ex);
array = null;
}

binaryReader.Close();
}

if(array == null)
return null;

var texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false);
texture2D.LoadImage(array);
return texture2D;
}

private static bool IDPatch(ItemDataBase __instance, ref int id, ref string name, ref string assetbundleName, ref int order, ref bool isNew)
{
name = name.Replace("\\n", "\n");
__instance.id = ((id > 999999 && id < 1000000000) ? id : (id % 1000));
__instance.name_LineFeed = name;
__instance.name = name.Replace("\n", string.Empty);
__instance.assetbundleDir = GlobalData.assetBundlePath;
__instance.assetbundleName = assetbundleName;
__instance.order = order;
__instance.isNew = isNew;

return false;
}

private static bool SetupPatch(ref AssetBundleController abc, ref Action<object, AssetBundleController, CustomDataListLoader> ___action, ref object datas)
{
string text = abc.directory + "/list/" + abc.assetBundleName + "_list.txt";
if(File.Exists(text))
{
Logger.LogInfo("Load list:" + text);
CustomDataListLoader customDataListLoader = new CustomDataListLoader();
customDataListLoader.Load(text);
___action(datas, abc, customDataListLoader);
return false;
}

return true;
}

private static string searchValue;

private static void SetupSearchPrefix(ref string search)
{
searchValue = search;
}

private static void SetupSearchPatch(ref object datas, ref string search, ref Action<object, AssetBundleController, CustomDataListLoader> ___action)
{
int num = searchValue.LastIndexOf("/");
var text = searchValue.Substring(0, num);

if(!Directory.Exists(GlobalData.assetBundlePath + "/list/" + text))
return;

foreach(var text3 in Directory.GetFiles(GlobalData.assetBundlePath + "/list/" + text, search + "_Mlist.txt"))
{
Logger.LogInfo("Load Mlist:" + text3);
StreamReader streamReader = new StreamReader(new FileStream(text3, FileMode.Open));
string assetBundleName = streamReader.ReadLine();
string contents = streamReader.ReadToEnd();
string tempFileName = Path.GetTempFileName();
File.WriteAllText(tempFileName, contents);
CustomDataListLoader customDataListLoader = new CustomDataListLoader();
customDataListLoader.Load(tempFileName);
File.Delete(tempFileName);
AssetBundleController assetBundleController2 = new AssetBundleController();
assetBundleController2.OpenFromFile(GlobalData.assetBundlePath, assetBundleName);
___action(datas, assetBundleController2, customDataListLoader);
assetBundleController2.Close(false);
}
}
}
}
36 changes: 36 additions & 0 deletions src/ModLoader.PlayHome/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("ModLoader.PlayHome")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ModLoader.PlayHome")]
[assembly: AssemblyCopyright("Copyright © 2019")]
[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("9f4a6b41-3465-4086-a1e2-023699b3f2ee")]

// 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")]
7 changes: 7 additions & 0 deletions src/ModLoader.PlayHome/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="IllusionLibs.BepInEx" version="5.0.1.1" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.BepInEx.Harmony" version="2.0.0-beta2" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.PlayHome.Assembly-CSharp" version="2018.3.11" targetFramework="net35" developmentDependency="true" />
<package id="IllusionLibs.PlayHome.UnityEngine" version="5.5.5" targetFramework="net35" developmentDependency="true" />
</packages>

0 comments on commit 0d1601c

Please sign in to comment.