Search the Community
Showing results for tags 'unityexplorer'.
-
Originally this guide was written for the game News Tower in the Steam Community - but given the overall process is applicable to all modern Unity games, I wanted to share it here as well. The main goal of the tutorial was to boost the "income" of Influence Points, while preserving the general game balance. Preface These things are considered cheating, and your save will probably be banned from submitting scores to the leader board. It doesn't block you from achievements though, so be cautious if you like to unlock them honestly as well. I will show you in an easy step-by-step way, how you can modify game elements in "real-time", without having to alter any game files. We'll do that to increase the yield we get from any Influence Point (IP) sources in-game, by simply doubling everything we get. The game gets less grindy, while still requiring you to work for IP. If you are only interested in changing something a single time, you can skip the Code and Hook sections, as they aren't that relevant for you. I'll probably build a normal mod for Influence Points in the future, but for now this must suffice. About the Process The stuff here will work in most (if not all) Unity games, just make sure you'll pick the right BepInEx/MelonLoader and UnityExplorer versions, if you try it out with another game. Preparing the Game To start: Download the latest BepInEx 5, e.g. BepInEx_win_x64_5.4.23.4 Extract/Copy the contents into your game folder, e.g. C:\SteamLibrary\steamapps\common\News Tower Start the game once. Load/Continue the game, and make a new save - just in case. Download the latest UnityExplorer BIE 5.X - Mono. Use this direct link, if you're unsure what to pick. Extract/Copy the plugin folder into ...\News Tower\BepInEx\plugins If your game folder looks like this in the end, you've done everything correctly: The Code Before we go into the game, I'll explain the logic to you, so you don't have to run random code you got "from a guy on the internet". And don't worry, everything is super simple. The gist of it: The game stores the amount of IP in an object called TowerStats, and every time you gain IP, it simply tells the TowerStats object just that; "Hey, add these 2 Influence Points". It does so by using a function called "AddInfluence", and passes the amount of IP to add, e.g. AddInfluence(2). We will intercept said function call, to multiply that number by 2, before it gets actually passed to AddInfluence. Here is the code, all lines starting with "//" are comments and explanations, and can be safely ignored and deleted - the program doesn't care. // "Prefix" means that we will do something before the original method is run // TowerStats __instance is the GameObject that holds the values we are interested in // ref float __0 is the amount of Influence Points that are supposed to be added. "__0" is just the (very bad) name of the variable, in the normal code it is called "amount" // Notice the "ref" tag; It tells the program to give us the actual "place" of the value (=reference), instead of simply telling us which value it has. This is important, as we not only want to read, but actually change it // __1 is irrelevant here static void Prefix(TowerStats __instance, ref float __0, bool __1) { // StringBuilder and sb.Append is just formatting stuff, so we see something in the log try { StringBuilder sb = new StringBuilder(); sb.Append("Multiplying Influnce. Before: ").Append(__0.ToString());; // This is the actual place of the "boost", __0 (=the Influence Points we get) // is multiplied with 2. // It's written like that because of floating point shenanigans, // but boils down to: amount = amount * 2 __0 = (float)((int)__0 * 2); // You can change this to anything you want, e.g. a higher multiplication, // or just a flat increase: // __0 = (float)((int)__0 * 5); // __0 = (float)((int)__0 + 2); sb.Append(" After: ").AppendLine(__0.ToString()); UnityExplorer.ExplorerCore.Log(sb.ToString()); } catch (System.Exception ex) { UnityExplorer.ExplorerCore .LogWarning($"Exception in Multiplier Mod; void TowerStats::AddInfluence(float amount, bool silent):\n{ex}"); } } And here is the code without the spam: static void Prefix(TowerStats __instance, ref float __0, bool __1) { try { StringBuilder sb = new StringBuilder(); sb.Append("Multiplying Influnce. Before: ").Append(__0.ToString());; __0 = (float)((int)__0 * 2); sb.Append(" After: ").AppendLine(__0.ToString()); UnityExplorer.ExplorerCore.Log(sb.ToString()); } catch (System.Exception ex) { UnityExplorer.ExplorerCore .LogWarning($"Exception in Multiplier Mod; void TowerStats::AddInfluence(float amount, bool silent):\n{ex}"); } } Applying the Hook A hook is essentially just another piece of code that is "attached" to something that is already present in the game. In our case, we want to do something when Influence Points are added, so we want to hook into the according class and method. After starting the game again, you'll be greeted with something like this - don't be intimidated! You can freely move, resize and close any windows you don't need, or hit F7 to hide it completely; Do just that, so you can continue/start a new game. After the game is fully loaded, find the right class for our hook: Search for the specific method for us to hook into. You can reduce the list by typing "add", so you're only shown those that have "add" in them: ឵ Now you can copy the code from above, and paste it inside: And that's it! Now you will always get double the amount of Influence Points from any source! Testing If you want to test the change, you can simply search for the TowerStats object and invoke our "AddInflunce" method. To do that, you'll have to find the object first: After you did that Scroll down to the AddInfluence method Click "Evaluate" Type in some value that you want to run a test with (into the first input field) Hit evaluate again Thereafter Check your Influence Points Check the Log window This is also the method you'd use to change other stats, e.g. money, resources, etc. - you only have to find the according GameObject they are stored in. That isn't always an easy task to do (or explain), but if you want to get a hang of how things work, simply use "Object Explorer"->"Scene Explorer" to find out how the game is structured. If objects are nested, you can "dig deeper" by simply clicking on "Inspect" in such a case. Note None of your game files are changed, and your game stays vanilla - which means that the changes are not permanent, and you'll have to apply the hook again after you restart the game. To uninstall the UnityExplorer, simply delete the folder from the BepInEx/plugins folder, or delete the BepInEx files altogether. Feel free to ask if you encounter problems - although I won't react to questions that can be solved by a 10 seconds google search.
-
- guide
- modding guide
-
(and 4 more)
Tagged with:
