Beispiel #1
0
        // [DllImport("kernel32.dll", SetLastError = true)]
        // [return: MarshalAs((UnmanagedType.Bool))]
        // static extern bool AllocConsole();
        //
        // public static void Main(string[] args)
        // {
        //  AllocConsole();
        //
        //  InitializeModLoader();
        // }

        public static void InitializeModLoader()
        {
            ModLogger.Init(GetLoaderRootFolder() + "\\Output.log");

            ModLogger.Log("Good Company Mod Loader initialized!");

            Harmony  harmony  = new Harmony("com.github.seppahbaws.gcmodloader");
            Assembly assembly = Assembly.GetExecutingAssembly();

            harmony.PatchAll(assembly);
            // harmony.PatchAll();

            ModLogger.LogInfo($"Patched {harmony.GetPatchedMethods().ToArray().Length} methods.");

            foreach (var method in harmony.GetPatchedMethods())
            {
                ModLogger.Log($"Patched method: {method}");
            }

            ModLogger.LogInfo("All mods loaded");

            // Harmony harmony = new Harmony("com.github.seppahbaws.gcmodloader");
            // Assembly assembly = Assembly.LoadFile("E:\\SSDLibrary\\steamapps\\common\\Good Company\\BepInEx\\plugins\\GoodCompanyTestMod.dll");
            // ModLogger.Log($"Mod name: {assembly.FullName}");
            // harmony.PatchAll(assembly);

            LogLoadedAssemblies();

            // ModLogger.Log($"DOORSTOP_PROCESS_PATH = {Environment.GetEnvironmentVariable("DOORSTOP_PROCESS_PATH")}");

            ModLogger.LogInfo($"mod loader rood folder: \"{GetLoaderRootFolder()}\"");
            ModLogger.LogInfo($"mods folder: \"{GetModsFolder()}\"");

            LoadMods(harmony);
        }
Beispiel #2
0
        public static void LoadMods(Harmony harmony)
        {
            List <string> files = Directory.GetFiles(GetModsFolder()).ToList();
            List <string> mods  = new List <string>();

            string     configText = File.ReadAllText(GetLoaderRootFolder() + "\\ModsConfig.json");
            ModsConfig config     = JsonConvert.DeserializeObject <ModsConfig>(configText);

            foreach (string file in files)
            {
                if (file.LastIndexOf(".dll") > -1)
                {
                    mods.Add(file);
                }
            }

            List <Mod>    configMods = config.Mods.ToList();
            List <string> loadedMods = new List <string>();

            ModLogger.LogInfo($"Mods found in config: {configMods.Count}");

            // Load mods
            foreach (Mod mod in configMods)
            {
                ModLogger.Log($"{mod.Name} ({mod.File}) enabled: {mod.Enabled}");
                if (!mod.Enabled)
                {
                    continue;
                }

                string fullModFile = GetModsFolder() + "\\" + mod.File;
                int    i           = mods.FindLastIndex(x => x == fullModFile);
                if (i <= -1)
                {
                    continue;
                }

                Assembly loadedMod = Assembly.LoadFile(fullModFile);
                harmony.PatchAll(loadedMod);
                loadedMods.Add(mod.Name);
            }

            ModsLoaded = loadedMods.Count;
            ModLogger.LogInfo($"Loaded {ModsLoaded} mods:");
            foreach (string loadedMod in loadedMods)
            {
                ModLogger.LogInfo(loadedMod);
            }

            LogLoadedAssemblies();
        }
        void LoadModel()
        {
            GCAssetReader.Model testModel = GCAssetReader.Reader.ReadFile(_testModelPath);

            ModLogger.LogInfo($"Loaded test model with {testModel.Vertices.Count} vertices and {testModel.Indices.Count} indices.");

            List <Vector3> vertices = new List <Vector3>(testModel.Vertices.Capacity);

            foreach (Vec3 v in testModel.Vertices)
            {
                vertices.Add(new Vector3(v.X, v.Y, v.Z));
            }

            List <Vector3> normals = new List <Vector3>(testModel.Normals.Capacity);

            foreach (Vec3 normal in testModel.Normals)
            {
                normals.Add(new Vector3(normal.X, normal.Y, normal.Z));
            }

            List <Vector2> uvs = new List <Vector2>(testModel.UVs.Capacity);

            foreach (Vec2 uv in testModel.UVs)
            {
                uvs.Add(new Vector2(uv.X, uv.Y));
            }

            StartCoroutine(LoadTexture(testModel.Texture));

            MeshFilter mf   = _obj.GetComponent <MeshFilter>();
            Mesh       mesh = new Mesh();

            mesh.vertices = vertices.ToArray();
            mesh.normals  = normals.ToArray();
            mesh.SetIndices(testModel.Indices.ToArray(), MeshTopology.Triangles, 0);
            mesh.uv       = uvs.ToArray();
            mf.sharedMesh = mesh;
        }