Modding Stonehearth's Graphics Test Program

@voxel_pirate I have seen some walk and following path functions where the .luac files from the idle functions are. These walk functions use x,y,z coordinates maybe the settlers can’t start in a cave but it should be possible to let them walk in. I have until now only modified the start_game.luac which initialize each asset and terrain elements and there the assets haven’t got any y-coordinates. So let us hope radiant is going to add that to the game if they haven’t done this already :wink:

You can now. And I’m sure that would help some budding modders out there (even me). Since you’ve already done it and we can share that why not save everyone else all that work? Thanks.

[quote=“voxel_pirate, post:46, topic:3540”]
So this is the first custom animation I was able to execute.[/quote]

So did you add that to the “idle effects”? Do you want to show us how you did that?

@Xavion You dropbox link is dead for the decompiled Lua.

1 Like

@Ramcat Here you go:

Here is the .ZIP file from @Xavion : Download stonehearth.zip

1 Like

For everyone who is interested. Here a small tutorial how to decompile most of the .luac files:

1. Get luadec 5.1

2. Extract it to a folder.

3. Extract from the .smod the .luac you want to decompile.

4. Open up your cmd and browse to the folder where you extracted luadec 5.1

5. To decompile enter something like this into your cmd:

6. After hitting enter the console outputs the decompiled content (marked red in my image):

7. Just copy the output to your favorite texteditor (mine is notped++) and save it as orginal_filename.luac

8. Exchange your created .luac with the original in the stonehearth.smod

Hope this helps someone. When i have forgotten something just reply to this post :wink:

Happy Modding everyone! :grin:

7 Likes

@Alesfatalis… I’m strongly considering changing your title to “Opener of Pandora’s Box”…

well done! :+1:

3 Likes

Actually I simply replaced the idle_breathe-animation with a custom one and did not try your approach to add it yet.

For sure I will share how to do it. However, to follow the description you will need the Add-On I am working on for Blender - or a similar one for another tool. If you do not have it you would need to read all the information from your animation (rotation, location, etc.) and write it manually into a file. So as long as the Add-On is not in a better shape it might not make sense to go too much into details… the progress can be followed here.

1 Like

@SteveAdamo Thanks for your kind words!

That would be an awesome title :grin:

First off I had a hunch that I confirmed, you can have the files with a .lua extension and it will still run stonehearth fine.

@Alesfatalis, There actually is a Y coordinate for them you just don’t use it for the place_item function. Here’s the relevant function.

MicroWorld.place_item = function(l_6_0, l_6_1, l_6_2, l_6_3, l_6_4)
  local entity = radiant.entities.create_entity(l_6_1)
  if l_6_4 then
    entity:add_component("unit_info"):set_faction(l_6_4)
  end
  radiant.terrain.place_entity(entity, Point3(l_6_2, 1, l_6_3))
  return entity
end

As you can see it as far as I can tell just sets all their Y value’s to 1 which seems to imply it’s a vertical displacement from the ground then aligned with the sames coordinates used for the terrain.

Also the batch code I used for decompiling folders of luac. It assumes that you have luadec on your desktop and than it will use it to change all .luac files in the folder it is in and all subfolders and so on into decompiled .lua files while deleting the .luac files. Essentially just put it in the stonehearth folder and run it to convert .luac to .lua, note however that on the files it completely fails on a error box will pop up, just hit cancel and it will keep going.

FOR /R %%f IN (*.luac) DO (
	C:\Users\Xavion\Desktop\luadec %%f > %%f_lua
	del "%%f"
	rename "%%f_lua" *.lua
)

EDIT TO AVOID DOUBLE POST; Arrgh opinions over this.

From another thread.

Done. I also played around with it a bit and discovered it’s not a template system like I first suspected, or it is just in the reverse of the normal order. So my current view is that it loads the json file for the entity or whatever and then it loads the file it extends from on top of that overwriting anything different with it’s version. That means that base_human would take precedent over human which seems kind of dodgy and also makes the use of “extends” for the syntax kind of weird as it’s kind of the other way around.

2 Likes

@voxel_pirate @Xavion @Miturion @Froggy @Alesfatalis - You’re all awesome!

Seeing what you’re doing with just the graphics test has got me all excited for the possibilities.

2 Likes

@Xavion Do you have a working decompiled micro_world.luac ?

Sure, while luadec51 didn’t quite work the unluac code for it worked fine.

3 Likes

It’s just that the names for them aren’t stored in the bytecode so it replace them with it’s own names. It makes it a bit harder to figure what they’re meant to be but it normally doesn’t provide too much trouble.

The decompiler uses this “code” for variable names (as far as I can tell): x_y_z where:
x = is class count
y = method count
z = argument count

So if you had two classes in one file and three methods in the second class with four arguments in the third method the last argument of the last method of the last class would be:
2_2_3

Not that, that does much except help you trace an argument name a little better. It seems the class count starts at “1” while the method and argument counts start at “0”. Odd that the decompiler uses “zero based” and “one based” counting in the same file. But as a software engineer who has been writing code since I was 14 (33 years) I would do away with all zero based counting systems. The thousands of times I’ve seen that lead to off-by-one errors in code.

3 Likes

I’m really impressed with what you all have been able to tinker with so far :slight_smile: if only weddings, work, and holidays didn’t coincide with the graphics test for me :stuck_out_tongue:

I have a really basic question on all this: Is decompiling going to be how we approach modding in SH? On a scale from 1-10, where is decompiling in the finished project?

When I was doing all of my research for my Fallout Mod, it appeared to me that ‘decompiling’ or otherwise reversing the core code of a program was considered to be a hack (hacking, etc, whatever verb fits), not a mod. I’m not a programmer, so the thought of breaking apart the engine is less appealing to me for a few reasons. 1) it’s hard, 2) it’s a lot less “sharable,” especially via steam.

So is our current approach going to have a future for SH, even as a possibility? Like will our current approach be one of many, or not possible due to Radiant program restrictions? Maybe @sdee would be the best person to ask.

Or perhaps I am misinterpreting what you all are doing, and all that is happening is that the mod-able files are being changed. Sort of like changing an html file, not the browser.

I’m fairly certain that everyone here is simply tinkering with what we have available. Modding the game will be a whole other process altogether. However, it’s much easier to design some a new fuel injection system if you know how the car works :wink:

3 Likes

I am convinced that it is not. As we can see, uncompiled code is already readable. I could imagine that the devs have compiled the code for some obscurity-reasons :wink:. Why do I think so? The devs always highlight that modding will be easy in the “final” product. Decomiling does not fit into such statements.

As mentioned in the initial post… take all the posts in this thread very cautious. You need to be fully aware that we are doing things which the devs might not have planned for us to do. The Graphics Test is what it is called… a test for the graphics engine. It is no showcase for modding or anything in this direction.

However as @Salletan mentiones… we can take some information out of it, which is kind of cool.

1 Like

oh, absolutely not… these amazing programmers and tinkerers are simply taking apart the materials that were provided as part of the graphics test, to see how it all works, and tweak/test accordingly…

in the preview release and of course with the public release, there will be modding tools at our disposal… this is one of the core ideas behind SH, so making it accessible to the average user is (i’m sure) very high on radiant’s list of priorities… :+1:

2 Likes

Me votes for Steve’s new title… birds whisperer :wink:.

You know, that’s exactly how I felt when I started working here, after 10 years in the industry. Just try–I dare you!–to switch between C++, Lua, and JS four or five times all in one day and not make one mistake that involves a semi-colon and/or curly-brace. :slight_smile:

Why unlearn when you can apply? :wink: We’re all fans of design methodology over here.

Yes, good instincts. :slight_smile:

Yes, well said. :wink:

Basically, we compiled the code so it would be super clear that the stuff in the graphics test wasn’t final code/api yet, and so that you, looking at it in all of its obfuscated glory, would be unable to forget that it’s unofficial.

Which is to say, we’re really impressed with how far you guys have gotten into it already. :slight_smile: :slight_smile: :slight_smile: We can’t wait to see what happens over the next few months.

9 Likes

indeed… we already know there will be some big players in the modding arena…

but (i imagine) this will be one of those rare occasions where there will be huge numbers of the more “casual” players who make the leap into modding as well… some of which will start small (modifying stats, etc.), and others who will undoubtedly introduce massive changes to the core game…

i see this place being an absolute madhouse over the holiday break, and well into the new year… :smile:

3 Likes