-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkipIntro.cs
More file actions
123 lines (100 loc) · 2.75 KB
/
Copy pathSkipIntro.cs
File metadata and controls
123 lines (100 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityModManagerNet;
using Harmony;
using System.Reflection;
using static UnityModManagerNet.UnityModManager;
using System.IO;
using System.Collections;
using UnityEngine.Video;
using System.Reflection.Emit;
namespace SkipIntro
{
static class Main
{
// Send a response to the mod manager about the launch status, success or not.
static bool Load(ModEntry modEntry)
{
var harmony = HarmonyInstance.Create(modEntry.Info.Id);
if (modEntry.GameVersion != gameVersion)
{
UnityModManager.Logger.Log($"Skip Intro expects {modEntry.GameVersion} but found {gameVersion}.");
}
harmony.PatchAll(Assembly.GetExecutingAssembly());
return true; // If false the mod will show an error.
}
}
static class SkipIntroParent
{
[HarmonyPatch(typeof(Boot))]
[HarmonyPatch("Start")]
public static class SkipIntro
{
static void Postfix(Boot __instance, ref int ___m_Stage)
{
Traverse traverse = Traverse.Create(__instance);
traverse.Field<bool>("m_SkipVideo").Value = true;
traverse.Field<VideoPlayer>("m_Video").Value.gameObject.SetActive(false);
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var ins = instructions.Last<CodeInstruction>(instruction => instruction.opcode == OpCodes.Ldarg_0);
var codes = instructions.ToList<CodeInstruction>();
var location = codes.IndexOf(ins);
for (int i = 0; i <= 2; i++)
{
instructions.ElementAt(location+i).opcode = OpCodes.Nop;
}
return codes;
}
}
[HarmonyPatch(typeof(Boot))]
[HarmonyPatch("LoadManager")]
public static class LoadManager
{
static bool Prefix(string Name)
{
UnityModManager.Logger.Log($"Loading {Name}");
return true;
}
}
[HarmonyPatch(typeof(Boot))]
[HarmonyPatch("Update")]
public static class UpdateSkipintro
{
static bool Prefix(Boot __instance, ref int ___m_Stage)
{
Traverse traverse = Traverse.Create(__instance);
int limit = traverse.Field<string[]>("m_Names").Value.Length;
if (___m_Stage != limit)
{
LoadManagerPass(traverse, ___m_Stage);
___m_Stage++;
if (___m_Stage == limit)
{
UnityModManager.Logger.Log($"Calling AllLoaded");
traverse.Method("AllLoaded").GetValue();
}
}
return false;
}
static void LoadManagerPass(Traverse traverse, int i)
{
string Name = traverse.Field<string[]>("m_Names").Value[i];
Type[] paramsTypes = new Type[]
{
typeof(string)
};
object[] arguments = new object[]
{
Name
};
var methods = traverse.Methods();
traverse.Method("LoadManager", paramsTypes, arguments).GetValue();
}
}
}
}