DOLjxxx Posted January 22, 2022 Share Posted January 22, 2022 I have long wanted to deal with modding in ONI. My knowledge of coding is very mediocre, but I'm a fast learner. I read the Cairath guide, figured out decompilation, working in Visual Studio, building, etc. But there were problems, it seems, with a simple task .... You need to change one value to another in a certain file ... If someone can help with a specific example of how to write code using Harmony, I would be very grateful ... Part of the code from the file - Assembly-CSharp - MethaneGeneratorConfig using TUNING; using UnityEngine; public class MethaneGeneratorConfig : IBuildingConfig { public const string ID = "MethaneGenerator"; public const float FUEL_CONSUMPTION_RATE = 0.09f; private const float CO2_RATIO = 0.25f; public const float WATER_OUTPUT_TEMPERATURE = 313.15f; private const int WIDTH = 4; private const int HEIGHT = 3; } I need to change for example - WATER_OUTPUT_TEMPERATURE - 313,15f => 350,15f How to write it in code using Harmony? Link to comment Share on other sites More sharing options...
DOLjxxx Posted January 24, 2022 Author Share Posted January 24, 2022 Can someone tell me why ONI MOD Uploader does not load the mod ??? There is a .dll file, there are two .yaml files, there is a preview picture... it gives error after error... What could be the problem? .... I read the forum, many have such a problem ... I looked at the log, the preview image does not want to load ... .... After 2 hours of trying... The mod loaded... Why this happened is not clear... it seems like a miracle Link to comment Share on other sites More sharing options...
pether Posted January 24, 2022 Share Posted January 24, 2022 I just saw your post. My understanding is that you succeeded and require help no longer? Link to comment Share on other sites More sharing options...
DOLjxxx Posted January 25, 2022 Author Share Posted January 25, 2022 11 hours ago, pether said: I just saw your post. My understanding is that you succeeded and require help no longer? I made my first mod - https://steamcommunity.com/sharedfiles/filedetails/?id=2729922307 ... But I still don't understand much... ...My main task now is to learn how to change the original code...To put it simply... I want the original method to be fully executed, but with the changes I made... For example: One of the original methods: Assembly-CSharp.dll - GameUtil public static float GetTemperatureConvertedToKelvin(float temperature) { switch (GameUtil.temperatureUnit) { case GameUtil.TemperatureUnit.Celsius: return temperature + 273.15f; case GameUtil.TemperatureUnit.Fahrenheit: return (float) (((double) temperature + 459.670013427734) * 5.0 / 9.0); default: return temperature; } I want the original method to be fully executed... only change...temperature + 273.15f => temperature + 300.00f How to write it correctly with Harmony? Hope you can help Link to comment Share on other sites More sharing options...
pether Posted January 25, 2022 Share Posted January 25, 2022 In Cairath's guide there is a link to Harmony documentation - you MUST read and understand it before doing any modding. At this point you can skip transpliers, but anything else is a MUST. In your case you will want to work with Postfix method. You can hijack method's returned result and you can access method's arguments. Now all you need to do is set desired value to the result using temperature + 300.00f value (or even easier - just add 26.85 to current result value, but this is very case-specific and you won't be able to shortcut like that in most cases) Link to comment Share on other sites More sharing options...
DOLjxxx Posted January 26, 2022 Author Share Posted January 26, 2022 15 hours ago, pether said: In Cairath's guide there is a link to Harmony documentation - you MUST read and understand it before doing any modding. At this point you can skip transpliers, but anything else is a MUST. In your case you will want to work with Postfix method. You can hijack method's returned result and you can access method's arguments. Now all you need to do is set desired value to the result using temperature + 300.00f value (or even easier - just add 26.85 to current result value, but this is very case-specific and you won't be able to shortcut like that in most cases) Reading does not mean understanding... I have already read the Harmony documentation several times, but for a person who has little experience in coding, in practice there are a lot of problems ... Can you write code for my example? I need to understand the SYNTAX of writing code... By writing the code, you will help me much more. I hope for you... Link to comment Share on other sites More sharing options...
pether Posted January 26, 2022 Share Posted January 26, 2022 14 minutes ago, DOLjxxx said: Can you write code for my example? I need to understand the SYNTAX of writing code public static void Postfix(float temperature, ref float __result) { if(GameUtil.temperatureUnit == GameUtil.TemperatureUnit.Celsius) __result = temperature + 300; } put that in public static class with Harmony annotations pointing to the class and method you want to patch (see Harmony docs)- since you provided the code I assume you know where to find that and I have no decompiled files at the moment to provide you with the details Also, I feel you will need more C# understadnig before making more mods - I can't teach you how to make most basic stuff in C# and you will need more of that to make other mods Link to comment Share on other sites More sharing options...
DOLjxxx Posted January 26, 2022 Author Share Posted January 26, 2022 19 minutes ago, pether said: public static void Postfix(float temperature, ref float __result) { if(GameUtil.temperatureUnit == GameUtil.TemperatureUnit.Celsius) __result = temperature + 300; } Thank you very much for help It was needed Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.