-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.cs
More file actions
219 lines (182 loc) · 14.3 KB
/
Plugin.cs
File metadata and controls
219 lines (182 loc) · 14.3 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using UnityEngine;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using static FF1PRAP.MyPatches;
using Last.Management;
using Il2CppSystem;
using System.Collections.Generic;
using System.IO;
using Il2CppInterop.Runtime;
using Last.Interpreter.Instructions.SystemCall;
using System.Runtime.InteropServices;
using Last.Data;
using Last.Interpreter;
using Last.Data.Master;
using Last.Map;
using static PostProcessLite;
using System.Xml;
using Last.Scene;
using Last.Data.User;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Last.Message;
using Last.Systems;
using System.Reflection;
using System.Linq;
namespace FF1PRAP;
public class PluginInfo
{
public const string NAME = "FF1 Pixel Remaster AP";
public const string VERSION = "0.5.17";
public const string GUID = "wildham.ff1pr.randomizer";
}
[BepInPlugin(PluginInfo.GUID, PluginInfo.NAME, PluginInfo.VERSION)]
public class FF1PR : BasePlugin
{
public static Dictionary<int, ItemData> PlacedItems;
public override void Load()
{
// Create Logger
InternalLogger.SetLogger(base.Log);
InternalLogger.LogInfo($"Plugin {PluginInfo.NAME} v{PluginInfo.VERSION} is loaded! ({PluginInfo.GUID})");
// Create Session Manager
SessionManager.Create();
// Create Behaviours
ClassInjector.RegisterTypeInIl2Cpp<Archipelago>();
ClassInjector.RegisterTypeInIl2Cpp<Monitor>();
ClassInjector.RegisterTypeInIl2Cpp<ApItemWindow>();
RegisterTypeAndCreateObject(typeof(SettingsWindow), "settings gui");
//Application.runInBackground = Settings.RunInBackground;
// Apply all the patches
Harmony harmony = new Harmony(PluginInfo.GUID);
// Treasure Patch
harmony.Patch(AccessTools.Method(typeof(Last.Map.EventActionTreasure), "CreateTask"), new HarmonyMethod(AccessTools.Method(typeof(Patches), "Treasure_Prefix")));
// Item Patch
harmony.Patch(AccessTools.Method(typeof(Last.Management.OwnedItemClient), "AddOwnedItem", [typeof(Content), typeof(int)]), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "Items_Postfix")));
harmony.Patch(AccessTools.Method(typeof(ShopUtility), "BuyItem", [typeof(ShopProductData), typeof(int)]), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "BuyItemProduct_Post")));
// Gameflag Patch
harmony.Patch(AccessTools.Method(typeof(Last.Interpreter.DataStorage), "Set", [typeof(string), typeof(int), typeof(int)]), new HarmonyMethod(AccessTools.Method(typeof(Patches), "Gameflags_Postfix")));
// Script Patch
harmony.Patch(AccessTools.Method(typeof(Last.Map.MapAssetData), "GetScript"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GetScript_Postfix")));
// Encounter rate Patch
harmony.Patch(AccessTools.Method(typeof(Last.Map.MapModel), "GetRequiredStepsRange"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GetRequiredStepsRange_Post")));
// Entities Patch
//harmony.Patch(AccessTools.Method(typeof(MapUtility), "ParseMapObjectGroupData"), new HarmonyMethod(AccessTools.Method(typeof(Patches), "ParseMapObjectGroupData_Prefix")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.FieldController), "SetupEntities"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "SetupEntities_Post")));
// Instances
harmony.Patch(AccessTools.Method(typeof(Last.Management.MessageManager), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "MessageManagerInit_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Interpreter.DataStorage), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "DataStorageInit_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.GameStateTracker), "Start"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GameStateTrackerInit_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.UserDataManager), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "UserDataManagerInit_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Data.Master.MasterManager), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "MasterManagerInit_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.MapManager), "InitInsitance"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "MapManagerInit_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.FieldController), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "FieldControllerInit_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.OwnedItemClient), "AddOwnedItem", [typeof(Content), typeof(int)]), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "OwnedItemClientInit_Postfix")));
// Init injected classes
harmony.Patch(AccessTools.Method(typeof(SceneTitleScreen), "CreateInstance"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "CreateInstance_Post")));
// Saving/Loading game
harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "LoadSlot"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "LoadSaveDataFromBoot_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "GotoLoadSaveData"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "LoadSaveDataFromMenu_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "SaveSlot"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GetSavePath_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "Save", [typeof(int), typeof(SaveSlotData)]), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GetSavePathSlot_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "Save", [typeof(int), typeof(Action<bool>), typeof(bool)]), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GetSavePathAction_Post")));
// New game
harmony.Patch(AccessTools.Method(typeof(Serial.FF1.UI.KeyInput.NewGameWindowController), "UpdateStartWait"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "NewGame_Postfix")));
harmony.Patch(AccessTools.Method(typeof(Serial.FF1.UI.Touch.NewGameWindowController), "UpdateStartWait"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "NewGame_Postfix")));
// Loading State
harmony.Patch(AccessTools.Method(typeof(Last.Systems.Indicator.SystemIndicator), "Activate"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GetLoadingState_Post")));
// Resource Manager + Assets
harmony.Patch(AccessTools.Method(typeof(Last.Management.ResourceManager), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GetResourceManager_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.ResourceManager), "CheckCompleteAsset", [typeof(string)]), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "CheckCompleteAsset_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.ResourceManager), "CheckGroupLoadAssetCompleted", [typeof(string)]), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "CheckGroupLoadAssetCompleted_Post"))); // for credits
// Loading/Saving Screen State
harmony.Patch(AccessTools.Method(typeof(Last.UI.KeyInput.TitleWindowController), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "TitleWindowControllerInitialize_Post")));
harmony.Patch(AccessTools.Method(typeof(MessageManager), "ReplaceKeyToValue", [typeof(string), typeof(Il2CppSystem.Collections.Generic.Dictionary<string, string>)]), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "ReplaceKey_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.UI.KeyInput.SaveListController), "SetContentData"), new HarmonyMethod(AccessTools.Method(typeof(Patches), "SetContentData_Pre")));
// Boost Menu
harmony.Patch(AccessTools.Method(typeof(Last.UI.KeyInput.ConfigController), "InitializeGameBoosterSetting"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "GameBooster_Post")));
// Loading Map coordinates, we'll need at least the first for EF shuffle
//harmony.Patch(AccessTools.Method(typeof(Last.Map.LoadData), "NextMapData", [typeof(PropertyGotoMap), typeof(ViewType)]), new HarmonyMethod(AccessTools.Method(typeof(Patches), "NextMapProperty_Pre")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.FieldController), "OnCacheTelepoPoint"), new HarmonyMethod(AccessTools.Method(typeof(Patches), "OnCacheTelePoint_Pre")), new HarmonyMethod(AccessTools.Method(typeof(Patches), "OnCacheTelePoint_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.LoadData), "NextMapData", [typeof(int), typeof(int), typeof(ViewType)]), new HarmonyMethod(AccessTools.Method(typeof(Patches), "NextMapInt_Pre")));
// TelepoCache endpoints
harmony.Patch(AccessTools.Method(typeof(Last.Map.TelepoCache), "Peek"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "TelepoCache_Peek")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.TelepoCache), "Pop"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "TelepoCache_Pop")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.TelepoCache), "GetCacheItem"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "TelepoCache_Get")));
// Transport Patch
harmony.Patch(AccessTools.Method(typeof(Last.Data.User.OwnedTransportationData), "SetData"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "SetTransportationData_Post")));
/*
harmony.Patch(AccessTools.Method(typeof(Last.Management.UserDataManager), "AddOwnedTransportationList"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "AddOwnedTransportationList_Pre")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.UserDataManager), "SetTransportationData"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SetTransportationData_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.Management.UserDataManager), "InitializeOwnedTransportation"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "InitializeOwnedTransportation_Post")));
*/
//harmony.Patch(AccessTools.Method(typeof(Last.Data.User.OwnedTransportationData), "FromJson"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "OwnedTransportData_FromJson")));
//harmony.Patch(AccessTools.Method(typeof(Last.Data.User.OwnedTransportationData), "SetData"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SetTransportationData_Pre")));
// For monitoring and debugging
/*
harmony.Patch(AccessTools.Method(typeof(Last.Map.TelepoCache), "Add", [typeof(TelepoPointData)]), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "TelepoCache_Add_Point")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.TelepoCache), "CreateCacheItem"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "TelepoCache_Add_Int")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.TelepoCache), "Add", [typeof(TelepoCacheItem)]), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "TelepoCache_Add_Item")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.TelepoCache), "RemoveAll"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "TelepoCache_Remove")));
*/
/*harmony.Patch(AccessTools.Method(typeof(Last.Map.TransportationController), "CheckOkList"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "CheckOkList_Post")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.TransportationController), "SetData", [typeof(IMapAccessor), typeof(OwnedTransportationData), typeof(bool), typeof(bool)]), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SetDataData_Pre")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.TransportationController), "SetData", [typeof(IMapAccessor), typeof(Il2CppSystem.Collections.Generic.List<OwnedTransportationData>), typeof(bool), typeof(bool)]), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SetDataList_Pre")));
harmony.Patch(AccessTools.Method(typeof(Last.Map.FieldController), "TransportationEnabled"), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "TransportationEnabled_Pre")));*/
harmony.Patch(AccessTools.Method(typeof(Last.Map.FieldPlayerController), "SetMapHandle"), new HarmonyMethod(AccessTools.Method(typeof(Patches), "SetMapHandle_Pre")));
harmony.Patch(AccessTools.Method(typeof(Last.Interpreter.Integrator), "Initialize"), null, new HarmonyMethod(AccessTools.Method(typeof(Patches), "Integrator_Post")));
//
//harmony.Patch(AccessTools.Method(typeof(Last.Management.UserDataManager), "GetCompleteFlag"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "GetCompleteFlag_Post")));
//harmony.Patch(AccessTools.Method(typeof(Last.Management.UserDataManager), "SetTransportationData"), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SetTransportationData_Pre")));
//harmony.Patch(AccessTools.Method(typeof(Last.Map.SaveMapManager), "SetMapPointIn"), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SetMapPointIn_Pre")));
//harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "SaveSlot"), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SaveSlotPre")));
//harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "Save", [typeof(int), typeof(SaveSlotData)]), new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "SaveSlotDataPre")));
//harmony.Patch(AccessTools.Method(typeof(Last.Management.SaveSlotManager), "GetTargetSaveSlotData"), null, new HarmonyMethod(AccessTools.Method(typeof(MyPatches), "GetTargetSaveSlotDataPost")));
}
private static void RegisterTypeAndCreateObject(System.Type type, string name)
{
ClassInjector.RegisterTypeInIl2Cpp(type);
UnityEngine.Object.DontDestroyOnLoad(new GameObject(name, new Il2CppSystem.Type[]
{
Il2CppType.From(type)
})
{
hideFlags = HideFlags.HideAndDontSave
});
}
}
public class InternalLogger
{
private static ManualLogSource Logger;
public static void LogInfo(string message)
{
Logger.LogInfo(message);
}
public static void LogWarning(string message)
{
Logger.LogWarning(message);
}
public static void LogError(string message)
{
Logger.LogError(message);
}
public static void LogDebug(string message)
{
Logger.LogDebug(message);
}
public static void SetLogger(ManualLogSource logger)
{
Logger = logger;
}
// set this to true to trigger logging for all log testing messages
public static bool Testing = true;
public static void LogTesting(string message)
{
if (Testing)
{
Logger.LogInfo(message);
}
}
}