public static Command CreateInstance(String className, Client client, bool log = true) { if (log) { VRCModLogger.Log("Creating command instance " + className + ". Client: " + client); } if (commands.TryGetValue(className, out Type commandClass)) { try { Command command = (Command)Activator.CreateInstance(commandClass); long outId; lock (counter) { outId = (long)(counter.NextDouble() * long.MaxValue); } command.SetLog(log); command.SetClient(client); command.SetOutId(className + " " + outId); if (!runningCommands.TryGetValue(className, out Dictionary <string, Command> commandContainer)) { commandContainer = new Dictionary <String, Command>(); runningCommands.Add(className, commandContainer); } commandContainer.Add("" + outId, command); return(command); } catch (Exception e) { VRCModLogger.LogError(e.ToString()); } } return(null); }
private static IEnumerator CheckAvatarOriginalReleaseStatus(string blueprintId, string id, string authorId) { VRCModLogger.Log("[AvatarStealerChecker] Checking avatar " + blueprintId); using (WWW avtrRequest = new WWW(API.GetApiUrl() + "avatars/" + blueprintId + "?apiKey=" + API.ApiKey)) { yield return(avtrRequest); int rc = WebRequestsUtils.GetResponseCode(avtrRequest); if (rc == 200) { try { VRCModLogger.Log("[AvatarStealerChecker] " + avtrRequest.text); SerializableApiAvatar aa = JsonConvert.DeserializeObject <SerializableApiAvatar>(avtrRequest.text); if (!aa.releaseStatus.Equals("public") && !aa.authorId.Equals(authorId)) { VRCModLogger.Log("[AvatarStealerChecker] Avatar " + id + " is a private stealed avatar ! (" + blueprintId + ")"); checkedAvatars[id] = true; } } catch (Exception e) { VRCModLogger.LogError("[AvatarStealerChecker] " + e.ToString()); } } } }
private static IEnumerator AddAvatarToList(string avatarId, string avatarName) { bool found = false; foreach (string avatarfavId in AvatarFavMod.favoriteAvatarList) { if (avatarfavId == avatarId) { found = true; VRCModLogger.LogError("[VRCheatAvatarfileImporter] Avatar " + avatarName + " already exist in list"); break; } } if (!found) { using (WWW avtrRequest = new WWW(API.GetApiUrl() + "avatars/" + avatarId + "?apiKey=" + AvatarFavMod.GetApiKey())) { yield return(avtrRequest); int rc = WebRequestsUtils.GetResponseCode(avtrRequest); if (rc == 200) { string uuid = APIUser.CurrentUser?.id ?? ""; SerializableApiAvatar aa = null; try { aa = JsonConvert.DeserializeObject <SerializableApiAvatar>(avtrRequest.text); } catch (Exception e) { VRCModLogger.LogError("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": Unable to parse the API response. " + e); } if (aa != null) { if (aa.authorId != uuid) { if (aa.releaseStatus == "public") { VRCModLogger.Log("[VRCheatAvatarfileImporter] Adding avatar " + avatarName + " to the database"); yield return(AddAvatar(avatarId, avatarName)); } else { VRCModLogger.Log("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": This avatar is not public anymore (private)"); } } else { VRCModLogger.Log("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": This avatar is own avatar"); } } } else { VRCModLogger.Log("[VRCheatAvatarfileImporter] Unable to add the avatar " + avatarName + ": This avatar is not public anymore (deleted)"); } } } }
internal static IEnumerator CheckDownloadFiles() { string vrccedllPath = Values.VRCToolsDependenciesPath + "VRCCore-Editor.dll"; int buildNumber = -1; VRCModLogger.Log("[DependenciesDownloader] Getting game version"); PropertyInfo vrcApplicationSetupInstanceProperty = typeof(VRCApplicationSetup).GetProperties(BindingFlags.Public | BindingFlags.Static).First((pi) => pi.PropertyType == typeof(VRCApplicationSetup)); if (vrcApplicationSetupInstanceProperty != null) { buildNumber = ((VRCApplicationSetup)vrcApplicationSetupInstanceProperty.GetValue(null, null)).buildNumber; } VRCModLogger.Log("[DependenciesDownloader] Game build " + buildNumber); yield return(DownloadDependency(ModValues.discordrpcdependencyDownloadLink, "discord-rpc.dll")); yield return(DownloadDependency(ModValues.oharmonydependencyDownloadLink, "0Harmony.dll")); try { VRCModLogger.LogError("[DependenciesDownloader] Loading 0Harmony.dll"); Assembly.LoadFile(Values.VRCToolsDependenciesPath + "0Harmony.dll"); } catch (Exception e) { VRCModLogger.LogError("[DependenciesDownloader] Unable to load 0Harmony.dll: " + e); } }
private void LoadUserInfoScreen() { // Refresh Button VRCEUiButton btnRefresh = new VRCEUiButton("refresh", new Vector2(0f, 0f), "Refresh"); btnRefresh.OnClick += () => { if (string.IsNullOrEmpty(PageUserInfo.userIdOfLastUserPageInfoViewed)) { return; } string id = PageUserInfo.userIdOfLastUserPageInfoViewed; ApiCache.Invalidate <APIUser>(id); APIUser.FetchUser(id, user => { PageUserInfo pageUserInfo = VRCEUi.UserInfoScreen.GetComponent <PageUserInfo>(); if (pageUserInfo != null) { pageUserInfo.SetupUserInfo(user); } }, error => VRCModLogger.LogError($"Failed to fetch user of id {id}: {error}")); }; VRCMenuUtilsAPI.AddUserInfoButton(btnRefresh); }
public static void ClearSpecificList(this UiAvatarList list) { if (fieldCachedSpecificList == null) { FieldInfo[] npInstFields = typeof(UiAvatarList).GetFields(BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo fi in npInstFields) { if (fi.FieldType == typeof(Dictionary <string, ApiAvatar>)) { fieldCachedSpecificList = fi; VRCModLogger.Log("fieldCachedSpecificList: " + fieldCachedSpecificList); break; } } if (fieldCachedSpecificList == null) { VRCModLogger.LogError("[AvatarFav] No CachedSpecificList field found in UiAvatarList !"); return; } } ((Dictionary <string, ApiAvatar>)fieldCachedSpecificList.GetValue(list)).Clear(); list.ClearAll(); VRCModLogger.Log("Number of elements in list after clear: " + ((Dictionary <string, ApiAvatar>)fieldCachedSpecificList.GetValue(list)).Count); }
internal static void Patch() // TODO: Optimise this crap { //APMDPMJMOCD.DBBLBDCLNHJ = FJALLEGMKMA.Full; VRCModLogger.Log("[RamExploitPatcher] Creating Harmony instance"); HarmonyInstance harmonyInstance = HarmonyInstance.Create("vrctools.ramexploitpatcher"); VRCModLogger.Log("[RamExploitPatcher] Looking for NetworkingPeer.OnEvent method"); Type[] typesInAssembly = typeof(QuickMenu).Assembly.GetTypes(); MethodInfo method = null; foreach (Type type in typesInAssembly) { if (type.Name != "PunTurnManager") { method = type.GetMethod("OnEvent", BindingFlags.Public | BindingFlags.Instance); if (method != null) { break; } } } if (method != null) { VRCModLogger.Log("[RamExploitPatcher] Patching NetworkingPeer.OnEvent"); harmonyInstance.Patch(method, null, null, new HarmonyMethod(typeof(RamExploitPatcher).GetMethod("OnEventPatcher", BindingFlags.NonPublic | BindingFlags.Static))); VRCModLogger.Log("[RamExploitPatcher] Patch applied !"); } else { VRCModLogger.LogError("[RamExploitPatcher] Unable to found method NetworkingPeer.OnEvent !"); } }
private static bool HandleMessagePrefix(object __1) { VRCModLogger.LogError("[VRCTools] [OculusUtils] Handling oculus message"); try { ulong requestId = (ulong)__1.GetType().BaseType.BaseType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic).First(f => f.FieldType == typeof(ulong)).GetValue(__1); VRCModLogger.LogError("[VRCTools] [OculusUtils] requestId: " + requestId); lock (callbackActions) { if (callbackActions.TryGetValue(requestId, out Action <bool, string> action)) { VRCModLogger.LogError("[VRCTools] [OculusUtils] Found request with id " + requestId); try { string data = (string)__1.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic).First().Invoke(__1, new object[] { }); VRCModLogger.LogError("[VRCTools] [OculusUtils] data: " + data ?? "(null)"); action?.Invoke(data == null, data); } catch (Exception e) { VRCModLogger.LogError("[VRCTools] [OculusUtils] An error has occured while handling a callback of Oculus.Platform.Callback.HandleMessage: " + e); return(true); } callbackActions.Remove(requestId); return(false); } } } catch (Exception e) { VRCModLogger.LogError("[VRCTools] [OculusUtils] An error has occured while handling Oculus.Platform.Callback.HandleMessage call: " + e); } return(true); }
public static void RunCommand(String line, Client client) { string[] parts = line.Split(new char[] { ' ' }, 3); if (runningCommands.TryGetValue(parts[0], out Dictionary <string, Command> commandContainer) && commandContainer.TryGetValue(parts[1], out Command command)) { if (parts[2].StartsWith("ERROR")) { command.RemoteError(parts[2].Split(new char[] { ' ' }, 2)[1]); } else { command.Handle(parts[2]); } } else { if (commands.TryGetValue(parts[0], out Type commandClass)) { try { command = (Command)Activator.CreateInstance(commandClass); command.SetClient(client); command.SetOutId(parts[0] + " " + parts[1]); commandContainer = runningCommands[parts[0]]; if (commandContainer == null) { commandContainer = new Dictionary <String, Command>(); runningCommands.Add(parts[0], commandContainer); } commandContainer.Add(parts[1], command); Command commandHandled = command; Thread commandThread = new Thread(() => { if (commandHandled != null) { try { commandHandled.Handle(parts[2]); } catch (Exception e) { commandHandled.WriteLine("ERROR " + e.Message.ToUpper()); } } }); commandThread.Name = "COMMAND_" + parts[0] + "_" + parts[1]; commandThread.Start(); } catch (Exception e) { VRCModLogger.LogError(e.ToString()); } } else { client.WriteLine(parts[0] + " " + parts[1] + " ERROR COMMAND_NOT_FOUND"); } } }
void OnApplicationStart() { if (Config == null) { VRCModLogger.LogError("Failed to get config!"); } ModManager.StartCoroutine(Setup()); }
public static bool GetBool(string section, string name) { if (prefs.TryGetValue(section, out Dictionary <string, PrefDesc> prefsInSection) && prefsInSection.TryGetValue(name, out PrefDesc pref)) { return(pref.Value.Equals("1")); } VRCModLogger.LogError("Trying to get unregistered ModPref " + section + ":" + name); return(false); }
public override void RemoteError(string error) { base.RemoteError(error); if (Log) { VRCModLogger.LogError("[RPCCommand] Server returned error for RPC " + rpcId + " : " + error); } onError?.Invoke(error); }
public static void RegisterCommand(string name, Type command) { if (!commands.TryGetValue(name, out Type cmd)) { commands.Add(name, command); } else { VRCModLogger.LogError("[CCOM] Trying to register a command twice (" + name + ")"); } }
public static float GetFloat(string section, string name) { if (prefs.TryGetValue(section, out Dictionary <string, PrefDesc> prefsInSection) && prefsInSection.TryGetValue(name, out PrefDesc pref)) { if (float.TryParse(pref.Value, out float valueF)) { return(valueF); } } VRCModLogger.LogError("Trying to get unregistered ModPref " + section + ":" + name); return(0.0f); }
public static Color GetColor(string section, string name) { if (prefs.TryGetValue(section, out Dictionary <string, PrefDesc> prefsInSection) && prefsInSection.TryGetValue(name, out PrefDesc pref)) { if (ColorUtility.TryParseHtmlString(pref.Value, out Color valueC)) { return(valueC); } } VRCModLogger.LogError("Trying to get unregistered ModPref " + section + ":" + name); return(Color.white); }
// SETTERS public static void SetString(string section, string name, string value) { if (prefs.TryGetValue(section, out Dictionary <string, PrefDesc> prefsInSection) && prefsInSection.TryGetValue(name, out PrefDesc pref)) { pref.Value = value; VRCModLoader.ModPrefs.SetString(section, name, value); } else { VRCModLogger.LogError("Trying to save unknown pref " + section + ":" + name); } }
public void WriteLineSecure(string s) { try { client.WriteLineSecure(outId + " " + s); } catch (Exception e) { VRCModLogger.LogError(e.ToString()); RemoteError(e.Message); } }
// VRCTools ShowQuickMenuPage function internal static void ShowQuickmenuPage(string pagename) { QuickMenu quickmenu = QMStuff.GetQuickMenuInstance(); Transform pageTransform = quickmenu?.transform.Find(pagename); if (pageTransform == null) { VRCModLogger.LogError("[QMStuff] pageTransform is null !"); } if (currentPageGetter == null) { GameObject shortcutMenu = quickmenu.transform.Find("ShortcutMenu").gameObject; FieldInfo[] fis = typeof(QuickMenu).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Where((fi) => fi.FieldType == typeof(GameObject)).ToArray(); VRCModLogger.Log("[QMStuff] GameObject Fields in QuickMenu:"); int count = 0; foreach (FieldInfo fi in fis) { GameObject value = fi.GetValue(quickmenu) as GameObject; if (value == shortcutMenu && ++count == 2) { VRCModLogger.Log("[QMStuff] currentPage field: " + fi.Name); currentPageGetter = fi; break; } } if (currentPageGetter == null) { VRCModLogger.LogError("[QMStuff] Unable to find field currentPage in QuickMenu"); return; } } ((GameObject)currentPageGetter.GetValue(quickmenu))?.SetActive(false); QMStuff.GetQuickMenuInstance().transform.Find("QuickMenu_NewElements/_InfoBar").gameObject.SetActive(false); if (quickmenuContextualDisplayGetter != null) { quickmenuContextualDisplayGetter = typeof(QuickMenu).GetFields(BindingFlags.NonPublic | BindingFlags.Instance).FirstOrDefault((fi) => fi.FieldType == typeof(QuickMenuContextualDisplay)); } QuickMenuContextualDisplay quickmenuContextualDisplay = quickmenuContextualDisplayGetter?.GetValue(quickmenu) as QuickMenuContextualDisplay; if (quickmenuContextualDisplay != null) { currentPageGetter.SetValue(quickmenu, pageTransform.gameObject); typeof(QuickMenuContextualDisplay).GetMethod("SetDefaultContext", BindingFlags.Public | BindingFlags.Instance).Invoke(quickmenuContextualDisplay, new object[] { 0, null, null }); // This is the only way to pass the unknown enum type value } currentPageGetter.SetValue(quickmenu, pageTransform.gameObject); typeof(QuickMenu).GetMethod("SetContext", BindingFlags.Public | BindingFlags.Instance).Invoke(quickmenu, new object[] { 1, null, null }); // This is the only way to pass the unknown enum type value pageTransform.gameObject.SetActive(true); }
static PlayerUtils() { try { PropertyInfo propertyInfo = typeof(Player).GetProperties().First((PropertyInfo p) => p.PropertyType == typeof(APIUser)); PlayerUtils.getApiUserMethod = ((propertyInfo != null) ? propertyInfo.GetGetMethod() : null); } catch (Exception) { #if (DEBUG) VRCModLogger.LogError("[TeleporterVR] Hmmm... seems like PlayerUtils failed, you might need to restart your game."); #endif } }
internal static void HandleRpc(string sender, string rpcId, string data) { if (rpcListeners.TryGetValue(rpcId, out Action <string, string> listener)) { try { listener(sender, data); } catch (Exception e) { VRCModLogger.LogError("Error while handling rpc " + rpcId + ": " + e); } } }
public static void Init() { eventHandlers = new DiscordRpc.EventHandlers(); eventHandlers.errorCallback = (code, message) => VRCModLogger.LogError("[VRCTools] [Discord] (E" + code + ") " + message); presence.state = "Not in a world"; presence.details = "Not logged in" + " (" + (VRCTrackingManager.IsInVRMode() ? "VR" : "PC") + ")"; presence.largeImageKey = "logo"; presence.partySize = 0; presence.partyMax = 0; presence.startTimestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds; presence.partyId = ""; presence.largeImageText = "VRChat"; DeviceChanged(); try { string steamId = null; switch (VRCApplicationSetup._instance.ServerEnvironment) { case ApiServerEnvironment.Release: steamId = "438100"; presence.largeImageText += " Release"; break; case ApiServerEnvironment.Beta: steamId = "744530"; presence.largeImageText += " Beta"; break; case ApiServerEnvironment.Dev: steamId = "326100"; presence.largeImageText += " Dev"; break; default: break; } DiscordRpc.Initialize("404400696171954177", ref eventHandlers, true, steamId); DiscordRpc.UpdatePresence(ref presence); running = true; VRCModLogger.Log("[DiscordManager] RichPresence Initialised"); } catch (Exception e) { VRCModLogger.Log("[DiscordManager] Unable to init discord RichPresence:"); VRCModLogger.Log("[DiscordManager] " + e); } }
/*public static void Transmists() * { * Teleport.TPToStoredPos(); * }*/ public void SavePosition() { StorePos(out pos, out rot); if (Debug) { VRCModLogger.Log("[TeleporterVR] Position store key pressed!"); if (pos == new Vector3(0f, 0f, 0f)) { VRCModLogger.LogError("[TeleporterVR] There may have been an issue saving your position!"); } if (rot == new Quaternion(0f, 0f, 0f, 0f)) { VRCModLogger.LogError("[TeleporterVR] There may have been an issue saving your rotation!"); } } }
public void TPToStoredPos() { LoadPos(pos, rot); { VRCModLogger.Log("[TeleporterVR] Teleport to saved key pressed!"); if (VRCPlayer.Instance.transform.position != pos) { VRCModLogger.LogError("[TeleporterVR] Error adjusting position!"); } if (VRCPlayer.Instance.transform.rotation != rot) { VRCModLogger.LogError("[TeleporterVR] Error adjusting rotation!"); } } }
public static bool PhotonOnEvent(EventData photonEvent) { try { if (photonEvent.Code == 200) { if (photonEvent.Parameters.TryGetValue(245, out object hashtable)) { if (((Hashtable)hashtable).TryGetValue((byte)4, out object dicEntry_)) { object[] dicEntry = (object[])dicEntry_; /* OLD CODE, FAIL ACROSS UPDATES * if (dicEntry[0].GetType() == typeof(VRC_EventLog.DIPHJLDJBCF)) * { * VRC_EventLog.DIPHJLDJBCF eventLogEntry = (VRC_EventLog.DIPHJLDJBCF)dicEntry[0]; * if (eventLogEntry.GFJCLHMFEJC != 0) * { * VRCModLogger.Log("[RamExploitPatcher] Packet contains VRC_EventLog.EventLogEntry with CombinedNetworkId " + eventLogEntry.GFJCLHMFEJC); * return false; * } * } * else VRCModLogger.Log("[RamExploitPatcher] Packet 200 doesn't contains VRC_EventLog.EventLogEntry"); */ long combinedId = GetCombinedId(dicEntry[0]); if (combinedId != 0) { VRCModLogger.Log("[RamExploitPatcher] Packet contains VRC_EventLog.EventLogEntry with CombinedNetworkId " + combinedId); return(false); } } else { VRCModLogger.Log("[RamExploitPatcher] Packet 200 doesn't contains hashtable index 4"); } } else { VRCModLogger.Log("[RamExploitPatcher] Packet 200 doesn't contains index 245"); } } } catch (Exception e) { VRCModLogger.LogError("[PhotonLogFull] " + e); } return(true); }
public static void GetAccessToken(Action <string> onSuccess, Action <string> onError) { VRCModLogger.LogError("[VRCTools] [OculusUtils] Adding GetAccessToken callback to list"); lock (callbackActions) { callbackActions.Add(ovr_User_GetAccessToken(), new Action <bool, string>((success, message) => { if (success) { onSuccess?.Invoke(message); } else { onError?.Invoke(message); } })); } }
private static int ParseResponseCode(string statusLine) { int ret = 0; string[] components = statusLine.Split(' '); if (components.Length < 3) { VRCModLogger.LogError("invalid response status: " + statusLine); } else { if (!int.TryParse(components[1], out ret)) { VRCModLogger.LogError("invalid response code: " + components[1]); } } return(ret); }
public void Start() { EnableKeys = !EnableKeys; { VRCModLogger.Log("[TeleporterVR] Keys toggled!"); } if (EnableKeys && Input.GetKeyDown(KeyCode.F)) { StorePos(out pos, out rot); if (Debug) { VRCModLogger.Log("[TeleporterVR] Position store key pressed!"); if (pos == new Vector3(0f, 0f, 0f)) { VRCModLogger.LogError("[TeleporterVR] There may have been an issue saving your position!"); } if (rot == new Quaternion(0f, 0f, 0f, 0f)) { VRCModLogger.LogError("[TeleporterVR] There may have been an issue saving your rotation!"); } } } if (EnableKeys && Input.GetKeyDown(KeyCode.R)) { LoadPos(pos, rot); if (Debug) { VRCModLogger.Log("[TeleporterVR] Teleport to saved key pressed!"); if (VRCPlayer.Instance.transform.position != pos) { VRCModLogger.LogError("[TeleporterVR] Error adjusting position!"); } if (VRCPlayer.Instance.transform.rotation != rot) { VRCModLogger.LogError("[TeleporterVR] Error adjusting rotation!"); } } } }
void OnApplicationStart() { VRCModLogger.Log("Starting AskToUsePortal...."); harmonyInstance = HarmonyInstance.Create("atilion.asktouseportal"); // Patch try { harmonyInstance.Patch( typeof(PortalInternal).GetMethod("Enter", BindingFlags.Public | BindingFlags.Instance), new HarmonyMethod(GetType().GetMethod("Enter", BindingFlags.Static | BindingFlags.NonPublic)) ); VRCModLogger.Log("Patched PortalInternal.Enter"); } catch (Exception ex) { VRCModLogger.LogError(ex.ToString()); } VRCModLogger.Log("Started AskToUsePortal!"); }
public void StartConnection() { if (thread != null && thread.IsAlive) { VRCModLogger.LogError("[VRCMODNW] Unable to start connection: The connection thread is already started"); return; } thread = new Thread(() => { ClientThread(); while (autoReconnect) { Thread.Sleep(2000); ClientThread(); } }); thread.Name = "VRCMod Networking Thread (Listen)"; thread.IsBackground = true; thread.Start(); }
public static int GetResponseCode(WWW request) { int ret = 0; if (request.responseHeaders == null) { VRCModLogger.LogError("no response headers."); } else { if (!request.responseHeaders.ContainsKey("STATUS")) { VRCModLogger.LogError("response headers has no STATUS."); } else { ret = ParseResponseCode(request.responseHeaders["STATUS"]); } } return(ret); }