private static void RoomSettings_FindParent(On.RoomSettings.orig_FindParent orig, RoomSettings self, Region region) { CustomWorldMod.Log($"[RoomSettings] Finding parent... filePath [{self.filePath}]", false, CustomWorldMod.DebugLevel.FULL); try { orig(self, region); } catch (Exception e) { CustomWorldMod.Log($"[RoomSettings] Found illegal characters in a room settings file [{self.name}]. \nException: {e}", true); throw e; } }
private static void RoomSettings_FindParent(On.RoomSettings.orig_FindParent orig, RoomSettings self, Region region) { if (self.isTemplate) { string filePath = "World" + Path.DirectorySeparatorChar + "Regions" + Path.DirectorySeparatorChar + region.name + Path.DirectorySeparatorChar + self.name + ".txt"; /* * if (!File.Exists(Custom.RootFolderDirectory() + filePath)) * { * } */ //CustomWorldMod.CustomWorldLog($"Custom Regions: Finding custom room settings template [{filePath}]"); bool foundTemplate = false; foreach (KeyValuePair <string, string> keyValues in CustomWorldMod.activatedPacks) { string newPath = Custom.RootFolderDirectory() + CustomWorldMod.resourcePath + keyValues.Value + Path.DirectorySeparatorChar + filePath; if (File.Exists(newPath)) { foundTemplate = true; self.filePath = newPath; CustomWorldMod.Log($"Found template at [{newPath}]"); break; } } if (!foundTemplate && File.Exists(Custom.RootFolderDirectory() + filePath)) { self.filePath = Custom.RootFolderDirectory() + filePath; CustomWorldMod.Log($"Using vanilla template at [{self.filePath}] since custom was not found", false, CustomWorldMod.DebugLevel.FULL); } } else { // Mod didn't include Settings file if (!File.Exists(self.filePath)) { string regularRoomPath = Custom.RootFolderDirectory() + "World" + Path.DirectorySeparatorChar + "Regions" + Path.DirectorySeparatorChar + Regex.Split(self.name, "_")[0]; regularRoomPath += Path.DirectorySeparatorChar + "Rooms" + Path.DirectorySeparatorChar + self.name + "_Settings.txt"; if (File.Exists(regularRoomPath)) { self.filePath = regularRoomPath; } else { CustomWorldMod.Log($"Missing settings file for [{self.name}] - [{regularRoomPath}]", false, CustomWorldMod.DebugLevel.FULL); } /* * try * { * // Call vanilla FindRoomDirectory * // I copied this from Warp :flushed: * MethodInfo _WorldLoader_FindRoomFileDirectory = typeof(WorldLoader).GetMethod("FindRoomFileDirectory", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); * object returnValue = _WorldLoader_FindRoomFileDirectory.Invoke(null, new object[] { self.name, false }); * // * var method = typeof(WorldLoader).GetMethod("FindRoomFileDirectory"); * var ftn = method.MethodHandle.GetFunctionPointer(); * var func = (Func<string, bool, string>)Activator.CreateInstance(typeof(Func<string, bool, string>), null, ftn); * object returnValue = func(self.name, false); * * if (returnValue != null && returnValue is string s && File.Exists(s + "_Settings.txt")) * { * self.filePath = s + "_Settings.txt"; * } * else * { * CustomWorldMod.Log($"Error loading settings file for [{self.name}] - [{returnValue}]"); * } * * } catch (Exception e) { CustomWorldMod.Log($"Error invoking method [{e}]", true); } */ } } /* * else * { * //CustomWorldMod.Log($"Custom Regions: RoomSettings, room [{self.name}] is not template. FilePath [{self.filePath}]"); * Calling FindRoomFileDirectory will find the custom one * self.filePath = FindVanillaRoom(self.name, false) + "_Settings.txt"; * } */ try { orig(self, region); } catch (Exception e) { CustomWorldMod.Log("Found illegal characters in a room settings file." + e, true); throw e; } }