Ghrommi Posted September 25, 2019 Share Posted September 25, 2019 Hi, I'm new to modding both generally and in ONI. I'm creating my first meaningful mod and want to enable rotation on the ration box. The reason is to be able to have action cell (?) on the right side instead of the left one. So question one is if the rotation even changes the action cell. I've seen the Rotate Everything mod and I'm trying to do the same, but somehow it just doesn't do anything. Here is my code: [HarmonyPatch(typeof(RationBoxConfig), "CreateBuildingDef")] public static class RationBoxConfig_CreateBuildingDef_Patch { public static void Postfix(BuildingDef __instance) { __instance.PermittedRotations = PermittedRotations.FlipH; } } Seems pretty straightforward, and the code is executed (I can log stuff), but I still have no possibility to rotate the ration box. Am I missing something? I also tried to just change action cell directly, but the closest thing I found resembling this is GetWorkOffset() function of the Workable class, and I don't even see a way to modify it. Any advice? Link to comment Share on other sites More sharing options...
Candide Posted September 26, 2019 Share Posted September 26, 2019 Mh... I am not sure that your code compiles. If it doesn't, I would have expected it to crash. Anyway, your problem is that you try to edit the instance, but what you should change is the result. When you look into the code, the function CreateBuildingDef is called when to create the actual GameObject. RationBoxConfig (the instance) is not carried over, which makes me wonder how you can set PermittedRotations, even though it's not a part of it's class... In short, your Patch should look like this: Quote public static void Postfix(BuildingDef __result) { __result.PermittedRotations = PermittedRotations.FlipH; } Edit: Btw __instance would be of the type RationBoxConfig, not BuildingDef. Link to comment Share on other sites More sharing options...
kelmen Posted September 26, 2019 Share Posted September 26, 2019 try put the rotation code in the building definition function, involved implement IBuildingConfig and override CreateBuildingDef Link to comment Share on other sites More sharing options...
Ghrommi Posted September 26, 2019 Author Share Posted September 26, 2019 13 hours ago, Candide said: Anyway, your problem is that you try to edit the instance, but what you should change is the result. That's it! After I changed it to __result, it works wonderfully! Thank you very much kind sir. 13 hours ago, Candide said: Edit: Btw __instance would be of the type RationBoxConfig, not BuildingDef. Makes me wonder how my code was even executed, if that is the case. Some error message on load would really help here. Link to comment Share on other sites More sharing options...
Candide Posted September 27, 2019 Share Posted September 27, 2019 In my experience, when you give harmony wrong stuff, like a typo in the method name, it will simply crash to desktop immediately. This also happens when you try to patch a method that is overloaded. In that case you must define [HarmonyPatch(Type[])] as explained in the wiki . Just telling you, because I had the same issue As you said, it would be easier when it put out an error message instead. 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.