Skip to content

Commit

Permalink
added support for downloading mods form ingame again, added a unpack …
Browse files Browse the repository at this point in the history
…feature where zip files will get automatically unpacked, fixed security issue where !modsuggest would just suggest unchecked mods and finally changed the font in the sign up screen to make it work with both capital and non capital letters
  • Loading branch information
X606 committed Jul 28, 2021
1 parent e01fc9b commit 0a9d3a3
Show file tree
Hide file tree
Showing 18 changed files with 11,053 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Mod Bot/InjectionTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ internal void Init(Type type, string methodName, InjectionType injectionType, Ty
MethodInfo selectedMethod = null;
if (methodParameters == null)
{
selectedMethod = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
selectedMethod = type.GetMethod(methodName, Injector.FLAGS);
}
else
{
selectedMethod = type.GetMethod(methodName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, methodParameters, null);
selectedMethod = type.GetMethod(methodName, Injector.FLAGS, null, methodParameters, null);
}
SelectedMethod = selectedMethod;

Expand Down
25 changes: 18 additions & 7 deletions Mod Bot/Internal/UI/ModSuggestingUI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Jint.Runtime.Debugger;
using ICSharpCode.SharpZipLib.Zip;
using Jint.Runtime.Debugger;
using ModLibrary;
using Newtonsoft.Json;
using System;
Expand Down Expand Up @@ -201,7 +202,8 @@ IEnumerator suggestMod(ModSuggestion mod)
yield break;
}
Directory.CreateDirectory(targetDirectory);
ZipFile.ExtractToDirectory(tempFile, targetDirectory);
FastZip fastZip = new FastZip();
fastZip.ExtractZip(tempFile, targetDirectory, null);

ModsManager.Instance.ReloadMods();

Expand Down Expand Up @@ -285,19 +287,28 @@ IEnumerator onModSuggest(string suggester, string modId)
yield break;
}

UnityWebRequest unityWebRequest = UnityWebRequest.Get("https://modbot.org/api?operation=getModData&id=" + modId);
unityWebRequest.timeout = 5;
yield return unityWebRequest.SendWebRequest();
UnityWebRequest unityDataWebRequest = UnityWebRequest.Get("https://modbot.org/api?operation=getModData&id=" + modId);
UnityWebRequest unityVerifiedWebRequest = UnityWebRequest.Get("https://modbot.org/api?operation=isModVerified&modId=" + modId);
unityDataWebRequest.timeout = 5;
unityVerifiedWebRequest.timeout = 5;
yield return unityDataWebRequest.SendWebRequest();
yield return unityVerifiedWebRequest.SendWebRequest();

if (!string.IsNullOrWhiteSpace(unityWebRequest.error))
if (!string.IsNullOrWhiteSpace(unityDataWebRequest.error) || !string.IsNullOrWhiteSpace(unityVerifiedWebRequest.error))
{
TwitchManager.Instance.EnqueueChatMessage("Error while trying to fetch mod data. MrDestructoid");
yield break;
}

try
{
string response = unityWebRequest.downloadHandler.text;
if (unityVerifiedWebRequest.downloadHandler.text == "false")
{
TwitchManager.Instance.EnqueueChatMessage("That mod isn't verified SoonerLater");
yield break;
}

string response = unityDataWebRequest.downloadHandler.text;

if (response == "null")
{
Expand Down
4 changes: 3 additions & 1 deletion Mod Bot/Mod Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@
<Reference Include="Esprima, Version=1.0.1258.0, Culture=neutral, PublicKeyToken=2e92ba9c8d81157f, processorArchitecture=MSIL">
<HintPath>..\packages\Esprima.1.0.1258\lib\net45\Esprima.dll</HintPath>
</Reference>
<Reference Include="ICSharpCode.SharpZipLib, Version=1.3.2.10, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.1.3.2\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="Jint, Version=0.0.0.0, Culture=neutral, PublicKeyToken=2e92ba9c8d81157f, processorArchitecture=MSIL">
<HintPath>..\packages\Jint.3.0.0-beta-1715\lib\net45\Jint.dll</HintPath>
</Reference>
Expand All @@ -196,7 +199,6 @@
<HintPath>..\UsedDlls\System.Core.dll</HintPath>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Runtime">
<HintPath>..\UsedDlls\System.Runtime.dll</HintPath>
</Reference>
Expand Down
43 changes: 38 additions & 5 deletions Mod Bot/ModHandling/ModDownloading/ModDownloadInfoItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using UnityEngine.Networking;
using System.IO;
using System.Diagnostics;
using ICSharpCode.SharpZipLib.Zip;

namespace InternalModBot
{
Expand Down Expand Up @@ -94,11 +95,42 @@ void onBrowseButtonClicked()
*/
}

static IEnumerator downloadModFileAndLoadAsync(string url)
IEnumerator downloadModFileAndLoadAsync(string url)
{
// yield return 0;

// Reverted
if (ModsManager.Instance.GetLoadedModWithID(_underlyingModInfo.UniqueID) != null)
{
throw new Exception("That mod is already installed");
}

UnityWebRequest webRequest = UnityWebRequest.Get("https://modbot.org/api?operation=downloadMod&id=" + _underlyingModInfo.UniqueID);

yield return webRequest.SendWebRequest();

byte[] data = webRequest.downloadHandler.data;

string tempFile = Path.GetTempFileName();
File.WriteAllBytes(tempFile, data);

string folderName = _underlyingModInfo.DisplayName;
foreach (char invalidCharacter in Path.GetInvalidFileNameChars())
{
folderName = folderName.Replace(invalidCharacter, '_');
}

string targetDirectory = ModsManager.Instance.ModFolderPath + folderName;
if (Directory.Exists(targetDirectory))
{
throw new Exception("That mod is already installed");
}
Directory.CreateDirectory(targetDirectory);
FastZip fastZip = new FastZip();
fastZip.ExtractZip(tempFile, targetDirectory, null);


ModsManager.Instance.ReloadMods();

File.Delete(tempFile);
/*
UnityWebRequest webRequest = UnityWebRequest.Get(url);
yield return webRequest.SendWebRequest();
Expand All @@ -114,7 +146,8 @@ static IEnumerator downloadModFileAndLoadAsync(string url)
ModsManager.Instance.ReloadMods();
ModsPanelManager.Instance.ReloadModItems();
}
*/
}

IEnumerator downloadModBytesAndLoadAsync(string url)
{
Expand Down
14 changes: 14 additions & 0 deletions Mod Bot/ModHandling/ModsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using HarmonyLib;
using Newtonsoft.Json;
using System.Diagnostics;
using ICSharpCode.SharpZipLib.Zip;

namespace InternalModBot
{
Expand Down Expand Up @@ -114,6 +115,19 @@ bool reloadAllMods(List<ModLoadError> errors)
{
unloadAllLoadedMods();

// first we take a pass to see if there any zip files we want to convert into folders
string[] zipFiles = Directory.GetFiles(ModFolderPath, "*.zip");
foreach (string zipFilePath in zipFiles)
{
string newDirectory = ModFolderPath + Path.GetFileNameWithoutExtension(zipFilePath);
Directory.CreateDirectory(newDirectory);
FastZip fastZip = new FastZip();
fastZip.ExtractZip(zipFilePath, newDirectory, null);
File.Delete(zipFilePath);

debug.Log("Unpacked " + Path.GetFileName(zipFilePath) + "...");
}

string[] folders = Directory.GetDirectories(ModFolderPath);
List<ModInfo> modsToLoad = new List<ModInfo>();
foreach(string folderPath in folders)
Expand Down
2 changes: 1 addition & 1 deletion Mod Bot/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Mod Bot/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ModBotVersion" xml:space="preserve">
<value>2.0</value>
<value>2.0.1</value>
<comment>The current version of Mod-Bot</comment>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Expand Down
1 change: 1 addition & 0 deletions Mod Bot/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<package id="Esprima" version="1.0.1258" targetFramework="net45" />
<package id="Jint" version="3.0.0-beta-1715" targetFramework="net45" />
<package id="MoonSharp" version="2.0.0.0" targetFramework="net45" />
<package id="SharpZipLib" version="1.3.2" targetFramework="net45" />
</packages>
Binary file modified UnityProject/Assets/AssetBundles/AssetBundles
Binary file not shown.
2 changes: 1 addition & 1 deletion UnityProject/Assets/AssetBundles/AssetBundles.manifest
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ManifestFileVersion: 0
CRC: 781925580
CRC: 1458525977
AssetBundleManifest:
AssetBundleInfos:
Info_0:
Expand Down
Binary file modified UnityProject/Assets/AssetBundles/modbot
Binary file not shown.
4 changes: 2 additions & 2 deletions UnityProject/Assets/AssetBundles/modbot.manifest
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ManifestFileVersion: 0
CRC: 550679962
CRC: 3795048527
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: ec10edfe8e3431eba3399c26558afdfa
Hash: f68b2d2c6304eb58d8bdf10d0faac8c1
TypeTreeHash:
serializedVersion: 2
Hash: 7003eb6ad59c2c7e955786ed10be32b4
Expand Down
8 changes: 4 additions & 4 deletions UnityProject/Assets/Prefabs/Canvas.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -3237,7 +3237,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 150d0e650a597a8c4f06dda7681d5701, type: 3}
m_Font: {fileID: 12800000, guid: 475631db19bb4f98475d87ef3ec24af8, type: 3}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
Expand Down Expand Up @@ -4861,7 +4861,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 150d0e650a597a8c4f06dda7681d5701, type: 3}
m_Font: {fileID: 12800000, guid: 475631db19bb4f98475d87ef3ec24af8, type: 3}
m_FontSize: 14
m_FontStyle: 2
m_BestFit: 0
Expand Down Expand Up @@ -5862,7 +5862,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 150d0e650a597a8c4f06dda7681d5701, type: 3}
m_Font: {fileID: 12800000, guid: 475631db19bb4f98475d87ef3ec24af8, type: 3}
m_FontSize: 14
m_FontStyle: 2
m_BestFit: 0
Expand Down Expand Up @@ -7425,7 +7425,7 @@ MonoBehaviour:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 150d0e650a597a8c4f06dda7681d5701, type: 3}
m_Font: {fileID: 12800000, guid: 475631db19bb4f98475d87ef3ec24af8, type: 3}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
Expand Down
2 changes: 1 addition & 1 deletion UnityProject/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
m_EditorVersion: 2018.4.25f1
m_EditorVersion: 2018.4.31f1
Binary file not shown.
Loading

0 comments on commit 0a9d3a3

Please sign in to comment.