Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
zeobviouslyfakeacc committed Jun 29, 2017
0 parents commit 8ddb2c9
Show file tree
Hide file tree
Showing 20 changed files with 784 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
.vs
obj
out
47 changes: 47 additions & 0 deletions ModLoaderInstaller.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{ADE91756-963B-4E39-BDF9-CB8F0C32D384}</ProjectGuid>
<OutputType>Library</OutputType>
<NoStandardLibraries>false</NoStandardLibraries>
<AssemblyName>ModLoader</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>out\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<RootNamespace>ModLoader</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine" />
</ItemGroup>
<ItemGroup>
<Compile Include="src\csharp\ModLoader.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSHARP.Targets" />
<ProjectExtensions>
<VisualStudio AllowExistingFolder="true" />
</ProjectExtensions>
</Project>
15 changes: 15 additions & 0 deletions ModLoaderInstaller.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/.idea" />
<excludeFolder url="file://$MODULE_DIR$/.vs" />
<excludeFolder url="file://$MODULE_DIR$/obj" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
22 changes: 22 additions & 0 deletions ModLoaderInstaller.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 15
VisualStudioVersion = 15.0.26430.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModLoaderInstaller", "ModLoaderInstaller.csproj", "{ADE91756-963B-4E39-BDF9-CB8F0C32D384}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ADE91756-963B-4E39-BDF9-CB8F0C32D384}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ADE91756-963B-4E39-BDF9-CB8F0C32D384}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ADE91756-963B-4E39-BDF9-CB8F0C32D384}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ADE91756-963B-4E39-BDF9-CB8F0C32D384}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file added resources/AddModdedToVersionString.dll
Binary file not shown.
Binary file added resources/Harmony.dll
Binary file not shown.
Binary file added resources/ModLoader.dll
Binary file not shown.
Binary file added resources/Rewired_Core.xor
Binary file not shown.
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/csharp/Hook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Reflection;
using System.IO;
using UnityEngine;

namespace Rewired
{
public class InputManager_Base
{
public static void Awake()
{
// COPY START
try
{
Debug.Log("Loading mod loader...");
Assembly modLoaderAssembly = Assembly.LoadFrom("tld_Data/Managed/ModLoader.dll");
Type modLoaderType = modLoaderAssembly.GetType("ModLoader.ModLoader", true);
MethodInfo startMethod = modLoaderType.GetMethod("Start", new Type[0]);
startMethod.Invoke(null, new object[0]);
}
catch (Exception e)
{
Debug.LogError("Could not start mod loader!");
Debug.LogException(e);
}
// COPY END
}
}
}
52 changes: 52 additions & 0 deletions src/csharp/ModLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Reflection;
using System.IO;
using UnityEngine;

namespace ModLoader
{
public class ModLoader
{
public static void Start()
{
try
{
Debug.Log("Loading Harmony...");
Assembly harmonyAssembly = Assembly.LoadFrom("tld_Data/Managed/Harmony.dll");
Type harmonyInstanceType = harmonyAssembly.GetType("Harmony.HarmonyInstance", true);
MethodInfo createMethod = harmonyInstanceType.GetMethod("Create", new Type[] { typeof(string) });
MethodInfo patchAllMethod = harmonyInstanceType.GetMethod("PatchAll", new Type[] { typeof(Assembly) });
Debug.Log("Harmony loaded");

DirectoryInfo dir = new DirectoryInfo("mods");
FileInfo[] files = dir.GetFiles("*.dll");
foreach (FileInfo file in files)
{
Debug.Log("Loading mod " + file.Name);
// Load Assembly and dependencies. Just resolve if already loaded (same for dependencies)
Assembly assembly = Assembly.LoadFrom(file.FullName);

// Search all Types in Assembly for HarmonyPatch instructions
object harmonyInstance = createMethod.Invoke(null, new object[] { assembly.FullName });
patchAllMethod.Invoke(harmonyInstance, new object[] { assembly });

// Then call static "OnLoad" method on all types where this method is defined
foreach (Type type in assembly.GetTypes())
{
MethodInfo onLoad = type.GetMethod("OnLoad", new Type[0]);
if (onLoad != null)
{
onLoad.Invoke(null, new object[0]);
}
}
}
Debug.Log("All mods successfully loaded!");
}
catch (Exception e)
{
Debug.LogError("Loading mods failed!");
Debug.LogException(e);
}
}
}
}
14 changes: 14 additions & 0 deletions src/java/me/zeobviouslyfakeacc/modloaderinstaller/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.zeobviouslyfakeacc.modloaderinstaller;

public class Constants {

public static final String TLD_VERSION = "v0.426";
public static final String DLL_NAME = "Rewired_Core.dll";
public static final String XOR_NAME = "Rewired_Core.xor";
public static final long UNPATCHED_SIZE = 1418752L;
public static final long PATCHED_SIZE = 1418752L;
public static final String UNPATCHED_SHA1 = "77e4ea76ec93d357bf9272363700b9c92c99e9e";
public static final String PATCHED_SHA1 = "1f0b3258a14ab0b75c87b0ff949e98f05c6ec0c2";
public static final String MOD_LOADER_SHA1 = "2d93e8b605cd426ac6c1e1311e7d3b69b57723ab";
public static final String ERROR_SHA1 = "- ERROR -";
}
54 changes: 54 additions & 0 deletions src/java/me/zeobviouslyfakeacc/modloaderinstaller/CreatePatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package me.zeobviouslyfakeacc.modloaderinstaller;

import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;

import static java.nio.file.StandardOpenOption.CREATE_NEW;
import static java.nio.file.StandardOpenOption.READ;
import static java.nio.file.StandardOpenOption.WRITE;
import static me.zeobviouslyfakeacc.modloaderinstaller.Constants.DLL_NAME;
import static me.zeobviouslyfakeacc.modloaderinstaller.Constants.XOR_NAME;
import static me.zeobviouslyfakeacc.modloaderinstaller.FileUtils.hashFile;

public class CreatePatch {

public static void main(String[] args) throws Exception {
System.out.println("Verify that the original DLL is called");
System.out.println(" " + DLL_NAME + ".orig");
System.out.println("and that the patched DLL is called");
System.out.println(" " + DLL_NAME);
System.out.print("\nPath to tld_data\\Managed: ");

Scanner in = new Scanner(System.in);
Path managedDir = Paths.get(in.nextLine());
if (!Files.isDirectory(managedDir)) {
System.out.println("Invalid directory");
return;
}

Path resourcesDir = Paths.get("resources");
Path outputFile = resourcesDir.resolve(XOR_NAME);
Path origFile = managedDir.resolve(DLL_NAME + ".orig");
Path patchedFile = managedDir.resolve(DLL_NAME);

Files.deleteIfExists(outputFile);

try (FileChannel outputChannel = FileChannel.open(outputFile, WRITE, CREATE_NEW);
FileChannel origChannel = FileChannel.open(origFile, READ);
FileChannel patchedChannel = FileChannel.open(patchedFile, READ)) {

System.out.println("Unpatched size: " + origChannel.size() + "L");
System.out.println("Patched size: " + patchedChannel.size() + "L");
System.out.println("Unpatched SHA1: " + hashFile(origFile));
System.out.println("Patched SHA1: " + hashFile(patchedFile));
long maxSize = Math.max(origChannel.size(), patchedChannel.size());
FileUtils.xorFiles(origChannel, patchedChannel, outputChannel, maxSize);
}

Path modLoaderPath = resourcesDir.resolve("ModLoader.dll");
System.out.println("Mod Loader SHA1: " + hashFile(modLoaderPath));
}
}
54 changes: 54 additions & 0 deletions src/java/me/zeobviouslyfakeacc/modloaderinstaller/FileStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package me.zeobviouslyfakeacc.modloaderinstaller;

import javafx.scene.paint.Paint;

import static me.zeobviouslyfakeacc.modloaderinstaller.Constants.*;

public enum FileStatus {
NO_FILE("", "Patch", Paint.valueOf("BLACK")),
VALID_UNPATCHED("Valid, unpatched", "Patch", Paint.valueOf("GREEN")),
VALID_OUTDATED("Valid, outdated", "Update", Paint.valueOf("DARKORANGE")),
VALID_PATCHED("Valid, patched", "Unpatch", Paint.valueOf("GREEN")),
INVALID("Invalid", "Patch", Paint.valueOf("RED")),
ERROR("ERROR", "Patch", Paint.valueOf("RED"));

private final String displayName;
private final String buttonText;
private final Paint displayColor;

FileStatus(String displayName, String buttonText, Paint displayColor) {
this.displayName = displayName;
this.buttonText = buttonText;
this.displayColor = displayColor;
}

public String getDisplayName() {
return displayName;
}

public String getButtonText() {
return buttonText;
}

public Paint getDisplayColor() {
return displayColor;
}

public boolean isValid() {
return (this == VALID_UNPATCHED || this == VALID_OUTDATED || this == VALID_PATCHED);
}

public static FileStatus forHash(String dllHash, String modLoaderHash) {
if (dllHash == null || dllHash.isEmpty()) return NO_FILE;
switch (dllHash) {
case UNPATCHED_SHA1:
return VALID_UNPATCHED;
case PATCHED_SHA1:
return (MOD_LOADER_SHA1.equals(modLoaderHash)) ? VALID_PATCHED : VALID_OUTDATED;
case ERROR_SHA1:
return ERROR;
default:
return INVALID;
}
}
}
Loading

0 comments on commit 8ddb2c9

Please sign in to comment.