kkdevs / Patchwork

mod
13 stars 1 forks source link

BepInEx v4.0 Loader for mk9v5 #8

Closed SakuraMods closed 6 years ago

SakuraMods commented 6 years ago

I modify the loader if someone search it, it's work for me opposite the downloaded and now i can run it with mk9

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Reflection;
using Patchwork;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SakuraModBepin : MonoBehaviour {

    public bool hasBepin () {
        foreach (var ass in AppDomain.CurrentDomain.GetAssemblies ()) {
            if (ass.FullName.ToLower ().StartsWith ("bepinex")) {
                return true;
            }
        }

        return false;
    }

    public void Awake () {
        // its already in appdomain, it probably loaded correctly
        if (hasBepin ()) {
            print ("BepinEx already loaded and (probably) running ok.");
            return;
        }

        print ("Trying to fix BepinEx plugins");
        string path = Path.GetFullPath (Application.dataPath + "/../bepinex");
        try {
            foreach (var dll in Directory.GetFiles (path + "/core", "*.dll")) {
                try {
                    AppDomain.CurrentDomain.Load (AssemblyName.GetAssemblyName (dll));
                } catch {
                    print("Error loading " + dll);
                };
            }
        } catch {
            print("Error loading " + path + "/core");
        };

        if (!hasBepin ()) {
            try {
                AppDomain.CurrentDomain.Load (Application.dataPath + "/Managed/bepinex.dll");
            } catch {
                print ("Error loading bepinex in " + Application.dataPath + "/Managed/bepinex.dll");
                return;
            };
        }

        foreach (var dll in Directory.GetFiles (path, "*.dll")) {
            try {
                var an = AssemblyName.GetAssemblyName (dll);
                var ass = AppDomain.CurrentDomain.Load (an);
                foreach (var t in ass.GetExportedTypes ()) {
                    if (t.BaseType?.Name == "BaseUnityPlugin") {
                        gameObject.AddComponent (t);
                    }
                }
            } catch (Exception ex) {
                print (ex);
            };
        }
    }

}
billyboy12 commented 6 years ago

NICE! Which file does your code need to be inserted into? Or better yet, do you have a compiled version of your edited launcher?

SakuraMods commented 6 years ago

I only put this script into [Koikatu Root]/UserData/scripts/SakuraModBepin.cs and it's works

koikatu_be

billyboy12 commented 6 years ago

Oh, it's a script! I thought you were modifying Patchwork itself!

Does your script work with the VR mod? I can't control the camera of make the MC walk (same problems that happens with Patchwork without your script) and I'm getting things like "Cannot set field of view on this camera while VR is enabled." messages in Evaluiator.

1waP2toxuw commented 6 years ago

outdated