Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions AdvancedSafety/AdvancedSafetyMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace AdvancedSafety
{
internal partial class AdvancedSafetyMod : MelonMod
{
public static MelonLogger.Instance Logger;

internal static bool CanReadAudioMixers = true;
internal static bool CanReadBadFloats = true;

Expand All @@ -35,6 +37,8 @@ internal partial class AdvancedSafetyMod : MelonMod
public override void OnApplicationStart()
{
if (!CheckWasSuccessful || !MustStayTrue || MustStayFalse) return;

Logger = LoggerInstance;

AdvancedSafetySettings.RegisterSettings();
ClassInjector.RegisterTypeInIl2Cpp<SortingOrderHammerer>();
Expand All @@ -45,7 +49,7 @@ public override void OnApplicationStart()
}
catch (Exception ex)
{
MelonLogger.Error($"Error initializing Bundle Verifier: {ex}");
Logger.Error($"Error initializing Bundle Verifier: {ex}");
}

var matchingMethods = typeof(AssetManagement)
Expand Down Expand Up @@ -251,7 +255,7 @@ void Bfs(GameObjectWithPriorityData objWithPriority)
go.AddComponent<SortingOrderHammerer>();

if (MelonDebug.IsEnabled() || destroyedObjects > 100)
MelonLogger.Msg($"Cleaned avatar ({avatarManager.field_Private_ApiAvatar_0?.name}) used by \"{vrcPlayer.prop_VRCPlayerApi_0?.displayName}\" in {start.ElapsedMilliseconds}ms, scanned {scannedObjects} things, destroyed {destroyedObjects} things");
Logger.Msg($"Cleaned avatar ({avatarManager.field_Private_ApiAvatar_0?.name}) used by \"{vrcPlayer.prop_VRCPlayerApi_0?.displayName}\" in {start.ElapsedMilliseconds}ms, scanned {scannedObjects} things, destroyed {destroyedObjects} things");
}

private static IEnumerator CheckSpawnSounds(GameObject go, List<AudioSource> audioSourcesList)
Expand Down Expand Up @@ -303,7 +307,7 @@ private static IntPtr ObjectInstantiatePatch(IntPtr assetPtr, Vector3 pos, Quate
}
catch (Exception ex)
{
MelonLogger.Error($"Exception when cleaning avatar: {ex}");
Logger.Error($"Exception when cleaning avatar: {ex}");
}

return result;
Expand Down
4 changes: 2 additions & 2 deletions AdvancedSafety/AvatarHiding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ private static void CanUseCustomAvatarPostfix(ref bool __result)
if (ourBlockedAvatarAuthors.ContainsKey(apiAvatar.authorId) ||
ourBlockedAvatars.ContainsKey(apiAvatar.id))
{
MelonLogger.Msg(
AdvancedSafetyMod.Logger.Msg(
$"Hiding avatar on {apiUser.displayName} because it or its author is hidden");
// denyReason = 3;
__result = false;
}
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in CanUseCustomAvatarPatch: {ex}");
AdvancedSafetyMod.Logger.Error($"Exception in CanUseCustomAvatarPatch: {ex}");
}
}

Expand Down
8 changes: 4 additions & 4 deletions AdvancedSafety/BundleVerifier/BundleDlContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal bool PreProcessBytes()
}
catch (Exception ex)
{
MelonLogger.Error($"Error while initializing verifier internals: {ex}");
AdvancedSafetyMod.Logger.Error($"Error while initializing verifier internals: {ex}");
return false;
}

Expand All @@ -63,8 +63,8 @@ internal int ProcessBytes(byte[] bytes, int offset, int length)
}
catch (IOException ex)
{
MelonLogger.Error($"Received more bytes than declared for bundle URL {Url} (declared: {BundleDlInterceptor.GetTotalSize(OriginalBundleDownload)})");
MelonLogger.Error(ex.ToString());
AdvancedSafetyMod.Logger.Error($"Received more bytes than declared for bundle URL {Url} (declared: {BundleDlInterceptor.GetTotalSize(OriginalBundleDownload)})");
AdvancedSafetyMod.Logger.Error(ex.ToString());
DoBackSpew();
unsafe
{
Expand Down Expand Up @@ -100,7 +100,7 @@ internal void CompleteDownload()
if (exitCode != 0)
{
var cleanedUrl = BundleVerifierMod.SanitizeUrl(Url);
MelonLogger.Msg($"Verifier process failed with exit code {exitCode} ({VerifierExitCodes.GetExitCodeDescription(exitCode)}) for bundle uid={cleanedUrl.Item1}+{cleanedUrl.Item2}");
AdvancedSafetyMod.Logger.Msg($"Verifier process failed with exit code {exitCode} ({VerifierExitCodes.GetExitCodeDescription(exitCode)}) for bundle uid={cleanedUrl.Item1}+{cleanedUrl.Item2}");
BundleVerifierMod.BadBundleCache.Add(Url);
MelonDebug.Msg("Reporting completion without data");
// feed some garbage into it, otherwise it dies
Expand Down
2 changes: 1 addition & 1 deletion AdvancedSafety/BundleVerifier/BundleDlInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static int PreparePatch(IntPtr thisPtr)
if (ourInterceptedContext.TryGetValue(thisPtr, out var context) && context.IsBadUrl)
{
var cleanedUrl = BundleVerifierMod.SanitizeUrl(context.Url);
MelonLogger.Msg($"Bundle for ptr {thisPtr} uid={cleanedUrl.Item1}+{cleanedUrl.Item2} is pre-marked as bad, faking failed download");
AdvancedSafetyMod.Logger.Msg($"Bundle for ptr {thisPtr} uid={cleanedUrl.Item1}+{cleanedUrl.Item2} is pre-marked as bad, faking failed download");
// indicate that it should use the DL stream
Marshal.WriteInt32(thisPtr + 0x90, 1);
// and then indicate the downloader that we don't want the download
Expand Down
6 changes: 3 additions & 3 deletions AdvancedSafety/BundleVerifier/BundleDownloadMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ internal static bool Init()

if (!ourBundleDownloadOffsets.TryGetValue(unityPlayerHash, out var offsets))
{
MelonLogger.Error($"Unknown UnityPlayer hash: {unityPlayerHash}");
MelonLogger.Error("Bundle verifier will not work");
AdvancedSafetyMod.Logger.Error($"Unknown UnityPlayer hash: {unityPlayerHash}");
AdvancedSafetyMod.Logger.Error("Bundle verifier will not work");
return false;
}

Expand Down Expand Up @@ -91,7 +91,7 @@ private static IntPtr CreateCachedPatch(IntPtr scriptingObjectPtr, NativePatchUt
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in CreateCached patch: {ex}");
AdvancedSafetyMod.Logger.Error($"Exception in CreateCached patch: {ex}");
}
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion AdvancedSafety/BundleVerifier/BundleHashCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public BundleHashCache(string? cacheFile)
var readBytes = myHashWriterStream.Read(transferArray, 0, transferArray.Length);
if (readBytes != transferArray.Length)
{
MelonLogger.Error($"Failure to read {transferArray.Length} bytes from cached bad URL file");
AdvancedSafetyMod.Logger.Error($"Failure to read {transferArray.Length} bytes from cached bad URL file");
myHashWriterStream.Position = 0;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions AdvancedSafety/BundleVerifier/BundleVerifierMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static void OnApplicationStart(HarmonyLib.Harmony harmonyInstance)
}
catch (IOException ex)
{
MelonLogger.Error("Unable to extract bundle verifier app, the mod will not work");
MelonLogger.Error(ex.ToString());
AdvancedSafetyMod.Logger.Error("Unable to extract bundle verifier app, the mod will not work");
AdvancedSafetyMod.Logger.Error(ex.ToString());
return;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ private static IEnumerator CheckInstanceType()
if (!EnabledSetting.Value)
{
BundleDlInterceptor.ShouldIntercept = false;
MelonLogger.Msg($"Bundle intercept disabled in settings");
AdvancedSafetyMod.Logger.Msg($"Bundle intercept disabled in settings");
yield break;
}

Expand Down
6 changes: 3 additions & 3 deletions AdvancedSafety/PortalHiding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void InstantiateObjectPatch(IntPtr thisPtr, IntPtr objectNamePtr,
if (APIUser.CurrentUser?.id == apiUser.id) return;

if (MelonDebug.IsEnabled())
MelonLogger.Msg($"User {apiUser.displayName} dropped a portal");
AdvancedSafetyMod.Logger.Msg($"User {apiUser.displayName} dropped a portal");

string denyReason = null;
if (AdvancedSafetySettings.HidePortalsFromBlockedUsers.Value && IsBlockedEitherWay(apiUser.id))
Expand All @@ -62,13 +62,13 @@ private static void InstantiateObjectPatch(IntPtr thisPtr, IntPtr objectNamePtr,
if (dict.ContainsKey(networkId))
{
var someStruct = dict[networkId];
MelonLogger.Msg(denyReason);
AdvancedSafetyMod.Logger.Msg(denyReason);
MelonCoroutines.Start(HideGameObjectAfterDelay(someStruct.field_Public_GameObject_0));
}
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in portal hider patch: {ex}");
AdvancedSafetyMod.Logger.Error($"Exception in portal hider patch: {ex}");
}
}

Expand Down
6 changes: 3 additions & 3 deletions AdvancedSafety/ReaderPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ internal static void ApplyPatches()

if (!ourOffsets.TryGetValue(unityPlayerHash, out var offsets))
{
MelonLogger.Error($"Unknown UnityPlayer hash: {unityPlayerHash}");
MelonLogger.Error("Some features will not work");
AdvancedSafetyMod.Logger.Error($"Unknown UnityPlayer hash: {unityPlayerHash}");
AdvancedSafetyMod.Logger.Error("Some features will not work");
return;
}

Expand Down Expand Up @@ -238,7 +238,7 @@ private static unsafe long CountNodesDeepThunk(NodeContainer* thisPtr)
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in CountNodes patch: {ex}");
AdvancedSafetyMod.Logger.Error($"Exception in CountNodes patch: {ex}");
return 1;
}
}
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
<SpecificVersion>false</SpecificVersion>
<Private>false</Private>
<HintPath>$(MsBuildThisFileDirectory)Libs\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="0Harmony">
<SpecificVersion>false</SpecificVersion>
<Private>false</Private>
<HintPath>$(MsBuildThisFileDirectory)Libs\0Harmony.dll</HintPath>
</Reference>
<Reference Include="UnhollowerBaseLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<SpecificVersion>false</SpecificVersion>
Expand Down
2 changes: 1 addition & 1 deletion FavCat/CustomLists/CustomPickerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void Awake()
}
catch (Exception ex)
{
MelonLogger.Error(ex.ToString());
FavCatMod.Logger.Error(ex.ToString());
}
}

Expand Down
10 changes: 5 additions & 5 deletions FavCat/Database/DatabaseImageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ public Task TrimCache(long maxSize)

await TaskUtilities.YieldToMainThread();

MelonLogger.Msg($"Removed {cutoffPoint} images from cache");
FavCatMod.Logger.Msg($"Removed {cutoffPoint} images from cache");
}).ContinueWith(task =>
{
if (!task.IsFaulted) return;

MelonLogger.Warning("Image cache trim failed; assuming cache corrupted, clearing collections. Exception: " + task.Exception);
FavCatMod.Logger.Warning("Image cache trim failed; assuming cache corrupted, clearing collections. Exception: " + task.Exception);
myFileDatabase.GetCollection<LiteFileInfo<string>>("_files").DeleteAll();
myFileDatabase.GetCollection("_chunks").DeleteAll();
});
Expand Down Expand Up @@ -109,13 +109,13 @@ public async Task LoadImageAsync(string url, Action<Texture2D?> onDone)
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in onDone callback: {ex}");
FavCatMod.Logger.Error($"Exception in onDone callback: {ex}");
}
}
catch (Exception ex)
{
if (MelonDebug.IsEnabled())
MelonLogger.Warning($"Exception in image load, will delete offending image: {ex}");
FavCatMod.Logger.Warning($"Exception in image load, will delete offending image: {ex}");
myFileDatabase.FileStorage.Delete(url);
myImageInfos.Delete(url);
onDone(AssetsHandler.PreviewLoading.texture);
Expand Down Expand Up @@ -158,7 +158,7 @@ public Task StoreImageAsync(string url, Il2CppStructArray<byte> data)
catch (LiteException ex)
{
if (MelonDebug.IsEnabled())
MelonLogger.Warning($"Database exception in image store handler: {ex}");
FavCatMod.Logger.Warning($"Database exception in image store handler: {ex}");
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions FavCat/Database/LocalStoreDatabase.Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class LocalStoreDatabase
{
internal void RunBackgroundAvatarSearch(string text, Action<IEnumerable<StoredAvatar>> callback)
{
MelonLogger.Msg($"Running local avatar search for text {text}");
FavCatMod.Logger.Msg($"Running local avatar search for text {text}");
var ownerId = APIUser.CurrentUser.id;
Task.Run(() => {
var searchText = text.ToLowerInvariant();
Expand All @@ -31,7 +31,7 @@ internal void RunBackgroundAvatarSearch(string text, Action<IEnumerable<StoredAv

internal void RunBackgroundAvatarSearchByUser(string userId, Action<IEnumerable<StoredAvatar>> callback)
{
MelonLogger.Msg($"Running local avatar search for user {userId}");
FavCatMod.Logger.Msg($"Running local avatar search for user {userId}");
var ownerId = APIUser.CurrentUser.id;
Task.Run(() => {
var list = myStoredAvatars.Find(stored =>
Expand Down
2 changes: 1 addition & 1 deletion FavCat/Database/LocalStoreDatabase.Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void UpdateStoredPlayer(APIUser player)

internal void RunBackgroundPlayerSearch(string text, Action<IEnumerable<StoredPlayer>> callback)
{
MelonLogger.Msg($"Running local player search for text {text}");
FavCatMod.Logger.Msg($"Running local player search for text {text}");
Task.Run(() => {
var searchText = text.ToLowerInvariant();
var list = myStoredPlayers.Find(stored => stored.Name.Contains(searchText)).ToList();
Expand Down
2 changes: 1 addition & 1 deletion FavCat/Database/LocalStoreDatabase.World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class LocalStoreDatabase
{
internal void RunBackgroundWorldSearch(string text, Action<IEnumerable<StoredWorld>> callback)
{
MelonLogger.Msg($"Running local world search for text {text}");
FavCatMod.Logger.Msg($"Running local world search for text {text}");
Task.Run(() => {
var searchText = text.ToLowerInvariant();
var list = myStoredWorlds.Find(stored =>
Expand Down
4 changes: 2 additions & 2 deletions FavCat/Database/LocalStoreDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LocalStoreDatabase(string databasePath, string imageCachePath)
}
catch (Exception ex)
{
MelonLogger.Warning("Exception when creating image cache; assuming it's corrupted and deleting it. Exception: " + ex);
FavCatMod.Logger.Warning("Exception when creating image cache; assuming it's corrupted and deleting it. Exception: " + ex);
File.Delete(imageDbPath);
myImageDatabase = new LiteDatabase(new ConnectionString { Filename = imageDbPath, Connection = connectionType });
}
Expand Down Expand Up @@ -79,7 +79,7 @@ private void UpdateThreadMain()
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in DB update thread: {ex}");
FavCatMod.Logger.Error($"Exception in DB update thread: {ex}");
}
} else
Thread.Sleep(100);
Expand Down
19 changes: 11 additions & 8 deletions FavCat/FavCatMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ namespace FavCat
internal partial class FavCatMod : MelonMod
{
public static LocalStoreDatabase? Database;
public static MelonLogger.Instance Logger;

internal static FavCatMod Instance;

internal AvatarModule? AvatarModule;
internal WorldsModule? WorldsModule;
internal PlayersModule? PlayerModule;

internal static PageUserInfo PageUserInfo;

public override void OnApplicationStart()
{
Instance = this;
Logger = LoggerInstance;
if (!CheckWasSuccessful || !MustStayTrue || MustStayFalse) return;

Directory.CreateDirectory("./UserData/FavCatImport");
Expand All @@ -48,7 +51,7 @@ public override void OnApplicationStart()

FavCatSettings.RegisterSettings();

MelonLogger.Msg("Creating database");
Logger.Msg("Creating database");
Database = new LocalStoreDatabase(FavCatSettings.DatabasePath.Value, FavCatSettings.ImageCachePath.Value);

Database.ImageHandler.TrimCache(FavCatSettings.MaxCacheSizeBytes).NoAwait();
Expand Down Expand Up @@ -96,7 +99,7 @@ public void OnUiManagerInit()
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in avatar module init: {ex}");
Logger.Error($"Exception in avatar module init: {ex}");
}

try
Expand All @@ -106,7 +109,7 @@ public void OnUiManagerInit()
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in world module init: {ex}");
Logger.Error($"Exception in world module init: {ex}");
}

try
Expand All @@ -116,11 +119,11 @@ public void OnUiManagerInit()
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in player module init: {ex}");
Logger.Error($"Exception in player module init: {ex}");
}

PageUserInfo = GameObject.Find("UserInterface/MenuContent/Screens/UserInfo").GetComponent<PageUserInfo>();
MelonLogger.Msg("Initialized!");
Logger.Msg("Initialized!");
}

public override void OnUpdate()
Expand Down Expand Up @@ -202,7 +205,7 @@ public static void ImageSnifferPatch(IntPtr instancePtr, IntPtr asyncOperationPt
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in image downloader patch: {ex}");
FavCatMod.Logger.Error($"Exception in image downloader patch: {ex}");
}
}

Expand Down Expand Up @@ -238,7 +241,7 @@ private static void ApiSnifferBody(IntPtr @this)
}
catch (Exception ex)
{
MelonLogger.Error($"Exception in API sniffer patch: {ex}");
FavCatMod.Logger.Error($"Exception in API sniffer patch: {ex}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion FavCat/GlobalImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static void RunRequest(string url)

ourNextAllowedUpdate = Time.time + RequestDelay;

MelonLogger.Msg($"Performing image request to {url}");
FavCatMod.Logger.Msg($"Performing image request to {url}");
ImageDownloader.DownloadImage(url, 256, new Action<Texture2D>(tex =>
{
if (!Textures.TryGetValue(url, out var oldTex) || !oldTex)
Expand Down
Loading