Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPurple6411 committed Feb 15, 2021
1 parent ba1e342 commit 40d6af1
Show file tree
Hide file tree
Showing 25 changed files with 7,751 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Bepinex-Publicizer/Bepinex-Publicizer.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)' == '' ">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>
122 changes: 122 additions & 0 deletions Bepinex-Publicizer/Main.cs
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;
}
}
}
36 changes: 36 additions & 0 deletions Bepinex-Publicizer/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("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")]
4 changes: 4 additions & 0 deletions Bepinex-Publicizer/packages.config
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>
22 changes: 22 additions & 0 deletions Bepinex-Tools.sln
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 added Dependencies/BepInEx-5.4.5/core/0Harmony.dll
Binary file not shown.
Loading

0 comments on commit 40d6af1

Please sign in to comment.