-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba1e342
commit 40d6af1
Showing
25 changed files
with
7,751 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)' == '' ">Release</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{AF6224AE-B14E-4FFF-9400-77EE91F9F9D9}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Bepinex_Publicizer</RootNamespace> | ||
<AssemblyName>Bepinex-Publicizer</AssemblyName> | ||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<Deterministic>true</Deterministic> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>none</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Bepinex-Publicizer\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>none</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Main.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Reference Include="BepInEx"> | ||
<HintPath>..\Dependencies\BepInEx-5.4.5\core\BepInEx.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="dnlib, Version=3.3.2.0, Culture=neutral, PublicKeyToken=50e96378b6e77999, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\dnlib.3.3.2\lib\net45\dnlib.dll</HintPath> | ||
</Reference> | ||
<Reference Include="UnityEngine"> | ||
<HintPath>..\Dependencies\UnityEngine.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
<Reference Include="UnityEngine.CoreModule"> | ||
<HintPath>..\Dependencies\UnityEngine.CoreModule.dll</HintPath> | ||
<Private>False</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using BepInEx; | ||
using BepInEx.Logging; | ||
using dnlib.DotNet; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using FieldAttributes = dnlib.DotNet.FieldAttributes; | ||
using MethodAttributes = dnlib.DotNet.MethodAttributes; | ||
using TypeAttributes = dnlib.DotNet.TypeAttributes; | ||
|
||
namespace Bepinex_Publicizer | ||
{ | ||
[BepInPlugin(GUID, MODNAME, VERSION)] | ||
public class Main : BaseUnityPlugin | ||
{ | ||
#region[Declarations] | ||
|
||
public const string | ||
MODNAME = "Bepinex_Publicizer", | ||
AUTHOR = "MrPurple6411", | ||
GUID = AUTHOR + "_" + MODNAME, | ||
VERSION = "1.0.0.0"; | ||
|
||
internal readonly ManualLogSource log; | ||
|
||
#endregion | ||
|
||
public Main() | ||
{ | ||
log = Logger; | ||
} | ||
|
||
public void Awake() | ||
{ | ||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); | ||
|
||
foreach(Assembly assembly in assemblies) | ||
if (Path.GetDirectoryName(assembly.Location).Contains("Managed") && assembly.GetName().Name.ToLowerInvariant().StartsWith("assembly")) | ||
ProcessAssembly(assembly); | ||
} | ||
|
||
void ProcessAssembly(Assembly assembly) | ||
{ | ||
string assemblyPath = assembly.Location; | ||
string filename = assembly.GetName().Name; | ||
string outputPath = Path.Combine(Path.GetDirectoryName(assemblyPath), "publicized_assemblies"); | ||
string outputSuffix = "_publicized"; | ||
|
||
Directory.CreateDirectory(outputPath); | ||
|
||
string lastHash = null; | ||
string curHash = ComputeHash(assemblyPath); | ||
|
||
string hashPath = Path.Combine(outputPath, $"{filename}{outputSuffix}.hash"); | ||
|
||
if (File.Exists(hashPath)) | ||
lastHash = File.ReadAllText(hashPath); | ||
|
||
if (curHash == lastHash) | ||
return; | ||
|
||
log.LogMessage($"Making a public assembly from {filename}"); | ||
RewriteAssembly(assemblyPath).Write($"{Path.Combine(outputPath, filename)}{outputSuffix}.dll"); | ||
File.WriteAllText(hashPath, curHash); | ||
} | ||
|
||
static string ComputeHash(string assemblyPath) | ||
{ | ||
StringBuilder res = new StringBuilder(); | ||
using (SHA1 hash = SHA1.Create()) | ||
{ | ||
using (FileStream file = File.Open(assemblyPath, FileMode.Open, FileAccess.Read)) | ||
{ | ||
hash.ComputeHash(file); | ||
file.Close(); | ||
} | ||
|
||
foreach (byte b in hash.Hash) | ||
res.Append(b.ToString("X2")); | ||
} | ||
|
||
return res.ToString(); | ||
} | ||
|
||
static ModuleDef RewriteAssembly(string assemblyPath) | ||
{ | ||
ModuleDef assembly = ModuleDefMD.Load(assemblyPath); | ||
foreach (var type in assembly.GetTypes()) | ||
{ | ||
type.Attributes &= ~TypeAttributes.VisibilityMask; | ||
|
||
if (type.IsNested) | ||
type.Attributes |= TypeAttributes.NestedPublic; | ||
else | ||
type.Attributes |= TypeAttributes.Public; | ||
|
||
foreach (MethodDef method in type.Methods) | ||
{ | ||
method.Attributes &= ~MethodAttributes.MemberAccessMask; | ||
method.Attributes |= MethodAttributes.Public; | ||
} | ||
|
||
List<string> eventNames = new List<string>(); | ||
foreach (EventDef ev in type.Events) | ||
eventNames.Add(ev.Name); | ||
|
||
foreach (FieldDef field in type.Fields) | ||
{ | ||
if (!eventNames.Contains(field.Name)) | ||
{ | ||
field.Attributes &= ~FieldAttributes.FieldAccessMask; | ||
field.Attributes |= FieldAttributes.Public; | ||
} | ||
} | ||
} | ||
return assembly; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("Bepinex_Publicizer")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Bepinex_Publicizer")] | ||
[assembly: AssemblyCopyright("Copyright © 2021")] | ||
[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("af6224ae-b14e-4fff-9400-77ee91f9f9d9")] | ||
|
||
// 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")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="dnlib" version="3.3.2" targetFramework="net472" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31005.135 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bepinex-Publicizer", "Bepinex-Publicizer\Bepinex-Publicizer.csproj", "{AF6224AE-B14E-4FFF-9400-77EE91F9F9D9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{AF6224AE-B14E-4FFF-9400-77EE91F9F9D9}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{AF6224AE-B14E-4FFF-9400-77EE91F9F9D9}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {627A6ECF-AFCD-4092-BEE4-B620062207B8} | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
Oops, something went wrong.