oblivioncth Posted August 26, 2021 Share Posted August 26, 2021 I want to change the (entire) day time to be longer and mess around with that for a while, and from what I can tell the best way to do this is substitute a value for TUNING.SEG_TIME so that there's no need to mess with segment counts and break who knows how much, but simply make the segments themselves take longer. The obvious issue is that TUNING.SEG_TIME is used by everybody and their mother in other scripts and even other TUNING values, but I specifically don't want to influence any other game mechanics than the those directly related to day duration. After searching a bit, it became clear that the location this value is used that actually affects day length is components/clock.lua, where it appears 12 times. Modifying this file by switching those references with a different value works flawlessly, it's surprisingly simple. The problem? Implementing this as a mod seems like a nightmare The file was clearly not really thought of for modification purposes as almost everything in it is local and contained within the constructor. Using AddComponentPostInit and AddClassPostConstruct won't cut it because of all of the locals and since those are executed too late anyway. I tried using Upvaluehacker like so to see if it was worth attempting: local UpvalueHacker = GLOBAL.require("tools/upvaluehacker") local Clock = GLOBAL.require("components/clock") local function SetDefaultSegs() print("Infiltration Successful") end UpvalueHacker.SetUpvalue(Clock._ctor, SetDefaultSegs, "SetDefaultSegs") But the sever doesn't crash (which I'd expect by just demolishing this function) and that message isn't printed to the console. I'm not too experienced with lua but I'm guessing this is because SetDefaultSegs isn't actually an upvalue of the constructor since it is declared within the constructor itself. I was hoping it could still do the swap. Does anyone know of a way I can make these changes via a mod? Despite it generally being bad practice, I'd simply have the mod completely override clock.lua given the otherwise extensive changes that are needed to alter those values indirectly/the normal way, but I don't think that's possible. I just need to be able to swap those 12 references of TUNING.SEG_TIME in clock.lua ONLY or be able to replace all the functions that use them; though that would also require being able to get references to the variables that use some of those in the constructor itself and recalculate their initial values again in something like AddClassPostConstruct (though again they're local). Point being the TUNING.SEG_TIME references are used by functions and during local variable assignments within the constructor. Link to comment Share on other sites More sharing options...
Monti18 Posted August 27, 2021 Share Posted August 27, 2021 This really doesn't look like an easy task... The easiest solution would be to make your own clock.lua file, which would replace the original one. You just copy the contents and replace all instances of TUNING.SEG_TIME with the value you want. The big disadvantage is that if Klei ever changes something in clock.lua, you will also need to change it. Also if another modder has an own version of clock.lua, there will also be problems. But otherwise it should work perfectly. As for UpvalueHacker, you didn't use it properly, you must start from a function that is not local. But even if you make it work, I wouldn't recommend it as these functions are pretty costly and they would be called quite often which will make your game lag probably. If you don't want to make a new clock.lua, I would go with changing segment counts, as this will probably break less than anything else you could try 1 Link to comment Share on other sites More sharing options...
oblivioncth Posted August 27, 2021 Author Share Posted August 27, 2021 9 hours ago, Monti18 said: This really doesn't look like an easy task... The easiest solution would be to make your own clock.lua file, which would replace the original one. You just copy the contents and replace all instances of TUNING.SEG_TIME with the value you want. The big disadvantage is that if Klei ever changes something in clock.lua, you will also need to change it. Also if another modder has an own version of clock.lua, there will also be problems. But otherwise it should work perfectly. As for UpvalueHacker, you didn't use it properly, you must start from a function that is not local. But even if you make it work, I wouldn't recommend it as these functions are pretty costly and they would be called quite often which will make your game lag probably. If you don't want to make a new clock.lua, I would go with changing segment counts, as this will probably break less than anything else you could try Yea unfortunately its not a nice file. For the easy solution, I would have no problem doing that since other modifications to clock.lua are unlikely and this is mainly for personal use; however, (baring having screwed it up) I already tried that by simply having a mod with my own clock.lua under scripts/components and it didn't take precedence over the one in the datapack. Do I have to require it or do something else with it in modmain.lua to force it to load over the standard one? With UpvalueHacker, isn't the constructor itself global? I've seen other people use it more or less this way with components to access functions through calls that reside in the constructor, though in those cases the functions themselves didn't also reside in the constructor. Sadly the only two non _ctor, global functions in clock.lua don't call any of the local functions so the _ctor is the only option if it can work. You are right though in that it would definitely be expensive so I'd prefer to just have my own file outright override the existing one anyway. I know that generally is to be avoided, but given how poorly accessible this file is and how rare it seems that other mods touch it, I think it's probably the best solution all things considered if I can get the changes to take effect. Link to comment Share on other sites More sharing options...
Monti18 Posted August 30, 2021 Share Posted August 30, 2021 I think it should work by just adding your own clock.lua to components, I tested it quickly with some prints and it's working for me. Super Hound Waves also replaces the hounded component with their own, they have another liine in the modmain, you can try adding it if won't work: -- Override the hounded component with our own AddComponentPostInit("hounded",Class) Oh that's right, I didn't see that it was all in the constructor, but I also had some problems there with using the upvalue hacker in the contructor Yeah I would also say your own file is the best bet. You will perhaps also need to change shard_clock.lua if you have caves, so that they are correctly synchronized. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now