Author Topic: Modding Expeditions (KF)  (Read 45987 times)

Offline Holy_Diver

  • Holy Diver
  • Archmage of Light
  • *****
  • Posts: 2280
  • This account won't read/reply to Private Messages
Re: Modding Expeditions (KF)
« Reply #30 on: July 18, 2018, 08:56:42 pm »
 :coffee: Not trying to apply pressure, but do let us know if your interest ever wanes. FWIW I made a note the other day, to mention about what you had said, that 4096 is 1.0. You expressed in a PM uncertainty about the scale, in the game's coordinates. The MDL format uses 4096 for surface normals, however, positional coordinates use 1000 as 1.0.  I imagine that could look strange if KF does so, and your expectation is to see factors of 4096.

P.S. I forked your GitHub a while back... I often fork things, but usually they are mature projects. It can be insurance against the project evaporating into thin air, or a way to make small changes to be able to fit projects into build environments. At any rate... I was pretty unimpressed with GitHub just now to find that not only are forks frozen at the time of their forking, but also there are no conveniences for keeping them up-to-date. So suddenly GitHub is looking a lot less enticing. 

P.P.S. I'm especially interested in any findings to do with game's vertical elements, i.e. the sections with clearly layered floor plans. For example, if there is a 64x64 map (wherein tiles are functionally a palette) then is there up to 3 64x64 maps? Or if there is one, are the tiles fused? for example. Or if there are multiple maps in memory at a time, which would easily explain the connecting corridors. I've actually come across code in SOM that looks like multiple maps in memory... which it doesn't appear to use. Although I'm at a loss to come up with convincing alternative theories, I'm very much resigned to the reality being, ultimately, less glamorous.

Offline TheStolenBattenberg

  • Capricorn Crusher
  • **
  • Posts: 192
Re: Modding Expeditions (KF)
« Reply #31 on: July 19, 2018, 06:35:03 am »
Interest is still here very much here, my team just struck some success with the game the other day so I've had to write up some new APIs, which required me getting to grips with C# (didn't take as long as I thought, i don't like not being able to manage my own memory though).

Unfortunately however, my knowledge of reverse engineering does not appear to be enough to figure out how the rest of the MO format works.

Quote
Something else to look out for is something SOM uses called a CP or control-points file. It takes triangles artists put in the models and converts them into points (from their center) and then has extra data that tracks the points in every animation frame. This is just so the points don't have to be taken from the mesh data/calculated on the fly. They are sorted into categories based on their coloring.
I heard about that, and honestly thought the system was an excellent idea for expanding the capabilities of vertex morph animation. I actually integrated a very similar system into one of my engines, but rather than keeping the triangles, it looks for any triangles using certain 'point' materials, then calculates the center of the triangle for a position, then uses the direction from the position to the Apex to calculate a direction, then some fun cosine stuff to form a rotation. I liked this system because it allowed me to do skeletal techniques, like attach a head to a body, then use code the modify its rotation so it could face the way I was looking.

Quote
MM3D? Do you use it? It's interesting that you mention it, because I decided I would use that (defunct) project as the beginning of a modeling software geared for SOM developers. Something with vertex-morphing and palettes built into it. That will use COLLADA natively. I have some blog posts about its development on my website. It's called Daedalus, named after the DAE file format. I will start by rewriting the entire thing, but I find that it's better to develop software from a starting point than to just do it from scratch. It helps to get your brain's gears going, and I think it can be more attractive to say that some software had origins elsewhere.... it's less egotistical.
MM3D is what I consider to be an excellent middle format for game formats, as it supports both skeletal and vertex morph, internal textures and a few other things of importance. It's also the only software I've found that imports Milkshape3D animations correctly, which is my primary modelling tool. Despite blender and 3DS Max/Maya being allegedly much better, I think they're over complicated for game development.

Quote
It is a little mysterious. Something weird about SOM's models, is they are broken into small pieces, or clusters of triangles. This is actually not good on today's hardware, because it increases overhead by way of many unnecessary drawing calls. I don't know if that is strictly CPU overhead, or GPU also. If CPU it's probably negligible. Anyway, it's clearly a vertex caching scheme for SOM. Which was important in the early days, and still is for high polygon models.
From my time developing engines, it's neither overhead. With too many draw calls it simply stops the GPU from doing anything because the CPU will be busy sending data. I like to perform real time vertex batching to avoid it, but unfortunately this doesn't work for animated models. I think this didn't matter to much for older consoles since the GPU generally worked directly with the models themselves, using shared memory helped too. I think this is most apparent in TMD models, with their packet like system, in modern day technology emulating this exactly would require a separate batch/stream for each triangle type. It's very inefficient in modern times, because we need a vertex format which supports all features of each primitive, then just don't use the features of the format we don't need. This means there is a bunch of wasted data floating around in memory doing nothing, which requires to be sent to the GPU. I think partitioned models were done to avoid stretching and intersection of triangles during motion, before they knew how to make a triangle collapse on its self as skin would.

Quote
This is what I gathered yesterday. I can say that the white section which I'd not noticed, looks a lot like MDL deltas. You can see, 00, 01, FF, FE, these are byte sized deltas no doubt, small ones in this case, ranging from -2, -1, 0, 1... you know this. But whatever they are these are byte-size cues either to apply deltas forward/backward at a certain rate, or actual deltas, although because they are so small, it seems unlikely their units are millimeters if so. I mean, such micro adjustments would not be visible to the naked eye at PlayStation sample rates.
Ah, so you're saying that this information is specifying specific vertices in the model, and a motion of sorts? So for example, 'Vertex 11 moves in this direction'? Would the same information exist for scale or rotation? From what I know, rotation doesn't work too well in vertex morph, so I doubt it. Obviously when the format is finally figured out, I will 'bake' this information into a more standard vertex morph format, which true frame by frame animation as it is in MM3D.

Quote
P.S. I forked your GitHub a while back... I often fork things, but usually they are mature projects. It can be insurance against the project evaporating into thin air, or a way to make small changes to be able to fit projects into build environments. At any rate... I was pretty unimpressed with GitHub just now to find that not only are forks frozen at the time of their forking, but also there are no conveniences for keeping them up-to-date. So suddenly GitHub is looking a lot less enticing. 
I did wonder where that branch was. I do not plan on removing the project from github, even if I were to stop working on it. I love open source and I feel like their is joy to be had in being the result to someones furious searching for a solution on google. It's nice to think that now, someone someday may also want to modify King's Field, and will find that a lot of work has already been done for them, and I didn't want to release binaries only because it's good to learn, certainly on a topic like reverse engineering game formats, which no one will teach you.

Quote
P.P.S. I'm especially interested in any findings to do with game's vertical elements, i.e. the sections with clearly layered floor plans. For example, if there is a 64x64 map (wherein tiles are functionally a palette) then is there up to 3 64x64 maps? Or if there is one, are the tiles fused? for example. Or if there are multiple maps in memory at a time, which would easily explain the connecting corridors. I've actually come across code in SOM that looks like multiple maps in memory... which it doesn't appear to use. Although I'm at a loss to come up with convincing alternative theories, I'm very much resigned to the reality being, ultimately, less glamorous.
I haven't done much research into the files. I can't tell too much, but I'll add the T Extracting tonight and map tile viewing and you can have a look though the tilesets for yourself. I don't think they are fused from the bit of research I did, but I also don't think there are multiple maps. Honestly I'm not sure how it works since it feels as if the maps are a lot bigger than 64x64. There are only 9 files for each area of the game, 9 music tracks, 9 level file sets (tile, database, event/unknown) and there are 9 big 'RTIM' files, which is the texture data for these. If you think about something like the big mine, you'd think these would be a lot larger than 64x64. I might have simply miss-read the length of a tile entry, and it could be that there is 8000, which would be 128x128 (or around that number). I'll again write a tool for this, since that's the only way more information will be uncovered. I can already read the tilesets, and know the tile data, so it shouldn't be too much work.
Ashes to ashes, Dust to dust...
Honor to glory; And iron to rust.
Hate to bloodshed, From rise to fall.
If I never have to die; Am I alive at all?

Offline Holy_Diver

  • Holy Diver
  • Archmage of Light
  • *****
  • Posts: 2280
  • This account won't read/reply to Private Messages
Re: Modding Expeditions (KF)
« Reply #32 on: July 19, 2018, 09:21:48 am »
Well, I double checked the maps, and the one I looked at happened to be the Big Mine. It's 64x64. (See edit in following reply.)

I am pretty unfamiliar with Misfit Model 3D. I just did a review of available modeling software with source code, and decided its was the only one that met my criteria for a jumping off point. It's interesting to hear MM3D (format) may be of value... and I am pretty sure I knew nothing of a vertex-morph feature when I was looking at it. It certainly wasn't part of my criteria that led me to decide upon it. I basically just wanted a skeleton project that had soaked up hundreds of hours of thinking about basic modeling tools in terms of a UI so that I wouldn't have to repeat that exercise myself. I will refine whatever is there, and by the time I'm done I may chuck most if not all of it, but I find having a scaffolding is very helpful for real world projects.

Quote
I heard about that, and honestly thought the system was an excellent idea for expanding the capabilities of vertex morph animation. I actually integrated a very similar system into one of my engines, but rather than keeping the triangles, it looks for any triangles using certain 'point' materials, then calculates the center of the triangle for a position, then uses the direction from the position to the Apex to calculate a direction, then some fun cosine stuff to form a rotation. I liked this system because it allowed me to do skeletal techniques, like attach a head to a body, then use code the modify its rotation so it could face the way I was looking.

Well I'm not sure what you have in mind describes a CP exactly. But I'd be surprised if you don't find control points inside of Armored Code for mounting body parts onto. They are not related to vertex-morph animations.... I mean they are not deformers or anything especially remarkable. I mentioned them, in case you might realize that some data in one of your mystery files is that.

I will figure out the MO format. I am wrapping up the work I've been consumed with for many weeks, if not months off and on that amounts to a new major release for SOM. So I will probably be finding that ePsxe binary and trying to make your tools work for me. If I have success I may begin organizing the files. The work I finished yesterday is full featured tools for making "profiles" for SOM. That just happens to be the first step for converting KF2's files into SOM building-blocks.
« Last Edit: July 19, 2018, 09:42:46 am by Holy_Diver »

Offline Holy_Diver

  • Holy Diver
  • Archmage of Light
  • *****
  • Posts: 2280
  • This account won't read/reply to Private Messages
Re: Modding Expeditions (KF)
« Reply #33 on: July 19, 2018, 09:46:15 am »
EDITED: Actually the in game maps are 200x200 pixels. Each tile should be 3x3. That comes out to 66 and 2/3rds tiles per map.  The tiles have a weird property that makes them feel like they don't map directly to the drawn maps. I wonder if it's possible they are 4x4, would be 50x50. If so, that's bad for SOM. In general a 3x3 tiling maps to SOM's grid. The walls of the tiles just don't fall where you'd expect them to in a consistent way. This is why I thought maybe they are not really tiles. But your work suggests they are. Even if they are 3x3, it doesn't explain the extra 2/3rds. The maps show lines all the way up to the edge. But I think that the maps may be hand tweaked, or that their walls may fall outside the tile itself.

It's a bit of a mystery, however, I think that approximately 64x64 looks correct. It looks lie a round number in that neighborhood.

EDITED: Here is a picture, mapped onto SOM, in order to illustrate how the walls follow a 3x3 tiling, but the direction the walls face tends to dictate where they fall in the tiling. This is strange, because in SOM you can freely rotate tiles. It could mean that KF2 tiles do not rotate. Or that the map drawing system is tweaked to convert the walls into clean pixels. See how the doorways are typically asymmetric. Maybe there is free rotation, but there is a just a large selection of tiles with walls falling in different places.

P.S. I think I'm going to try that 50x50 theory out. I don't know if it has any grave implications. The tiles that come with SOM just tend to break down into 3x3 shapes. (edited: Although they are 2x2 like as well, especially SOM_MAP's tiles. The auto-generated in-game maps use 3x3 tiles. They tend to not looks as nice as KF's, so I can see why an artist might take some liberties with them.)
« Last Edit: July 19, 2018, 03:10:14 pm by Holy_Diver »

Offline Holy_Diver

  • Holy Diver
  • Archmage of Light
  • *****
  • Posts: 2280
  • This account won't read/reply to Private Messages
Re: Modding Expeditions (KF)
« Reply #34 on: July 19, 2018, 10:35:02 am »
Update: You may be right. It's hard to say anything conclusive, but a 2x2 tiling (vis-a-vis the map drawings) seems like a real possibility, since that is 100x100 just like SOM. It lines up with SOM, but you would kind of expect it to, since it's practically a 1:1 mapping with the pixels and its grid.

If each tile is 2x2 meters, and Alef is likely ~1.6 meters tall, then you can probably get a feel for scale. Although, I think that the FOV is very wide, so it can be hard to judge scale.

If you look at the attachment in my previous reply, wherever the arrowhead is in the game, that corridor would be about 12 meters wide with a 100x100 tiling, or 2x2 pixels per tile in the in-game maps. Unless the tiles are not 2 meters.... but that seems too wide.

If it is 100x100, maybe it is 1x1 meters. That would feel about the width of the larger corridors.
« Last Edit: July 19, 2018, 03:05:07 pm by Holy_Diver »

Offline Holy_Diver

  • Holy Diver
  • Archmage of Light
  • *****
  • Posts: 2280
  • This account won't read/reply to Private Messages
Re: Modding Expeditions (KF)
« Reply #35 on: July 19, 2018, 10:49:05 am »
FWIW I think I favor the 3x3 tiling. For 2x2 and 4x4 the two railroad tracks in the Big Mine that run parallel to one another cannot both fall on a 2x2 or 4x4 grid. That seems unlikely to me, because being even numbered, they should be symmetric. I think that any technique for projecting the tiles onto a picture would not change this.

Whereas, with 3x3 tiling, they fit together, if you assume that one is rotated, since it's running in reverse. I've always felt 3x3 looks good. I just don't understand why it doesn't line up neatly in the maps. I wonder if an artist went in and modified the maps by hand to give them a better appearance... something like adding hinting to fonts. I mean, when pixels are that dense a human touch can go a long way to making them appear more pleasant to the eye... even if that means misrepresenting the real coordinates.


EDITED: What about that screenshot where you transformed a tile into another tile? I guess it was changing that tile everywhere? By changing its model? Instead of changing the tiling. In any case, I will not be happy until there is a definitive answer in some form or other.
« Last Edit: July 19, 2018, 11:08:53 am by Holy_Diver »

Offline TheStolenBattenberg

  • Capricorn Crusher
  • **
  • Posts: 192
Re: Modding Expeditions (KF)
« Reply #36 on: July 19, 2018, 02:36:53 pm »
Quote
Well I'm not sure what you have in mind describes a CP exactly. But I'd be surprised if you don't find control points inside of Armored Code for mounting body parts onto. They are not related to vertex-morph animations.... I mean they are not deformers or anything especially remarkable. I mentioned them, in case you might realize that some data in one of your mystery files is that.

Yeah, I think I remember reading that the control points can direct where and in which direction magic will be projected from in enemies? The CP system just inspired the one I've got.

Quote
I will figure out the MO format. I am wrapping up the work I've been consumed with for many weeks, if not months off and on that amounts to a new major release for SOM. So I will probably be finding that ePsxe binary and trying to make your tools work for me. If I have success I may begin organizing the files. The work I finished yesterday is full featured tools for making "profiles" for SOM. That just happens to be the first step for converting KF2's files into SOM building-blocks.
Awesome. I'll make sure the extractor is prepared then.

Quote
Whereas, with 3x3 tiling, they fit together, if you assume that one is rotated, since it's running in reverse. I've always felt 3x3 looks good. I just don't understand why it doesn't line up neatly in the maps. I wonder if an artist went in and modified the maps by hand to give them a better appearance... something like adding hinting to fonts. I mean, when pixels are that dense a human touch can go a long way to making them appear more pleasant to the eye... even if that means misrepresenting the real coordinates.

EDITED: What about that screenshot where you transformed a tile into another tile? I guess it was changing that tile everywhere? By changing its model? Instead of changing the tiling. In any case, I will not be happy until there is a definitive answer in some form or other.
I feel as if it may be that someone played with the maps afterwards, and as if your 3x3 theory fits perfectly. The tiles can be rotated. I did change the tile but not a model. This is what I know so far about the way tiles are stored:
Quote
typedef struct {
   char Unknown;
   char Unknown;
   char Unknown;
   char Unknown;
   char Unknown;
   char TileMeshIndex;
   char TileHeight;
   char TileRotation;
   char CollisionMesh;
   char LightValue;
} Tile;
The unknown values don't appear to do anything, I think two of them change how the tile is rendered, and either one or two of them are some form of packet ID for the tile. I'm writing up that reader now to see if we can get more information, since MO files are currently taking too much of my focus from the other aspects.
« Last Edit: July 19, 2018, 08:13:10 pm by TheStolenBattenberg »
Ashes to ashes, Dust to dust...
Honor to glory; And iron to rust.
Hate to bloodshed, From rise to fall.
If I never have to die; Am I alive at all?

Offline Holy_Diver

  • Holy Diver
  • Archmage of Light
  • *****
  • Posts: 2280
  • This account won't read/reply to Private Messages
Re: Modding Expeditions (KF)
« Reply #37 on: July 19, 2018, 05:57:10 pm »
I'm going to edit to this later, just putting this here so you know I've read it. Gotta cook dinner first.

"Psycpros" is almost great... would make a great handle, except the element of dyslexia really goes too far. It makes you wonder who-or-what was translating this stuff, and did anyone read/play it. From what I can gather the seemingly classier PAL version produced by Sony used the same translation. There are a few more of these... but I can hardly remember them. Like I know Vortex is translated as "Bortecks" or something even more outlandish. And I recall that Refuge is a weird nonsense word too. (Edited: "Refusal"... I'm now able to recall.) It's worse to just make things up (phonetically?) seeing as all of the magics are extremely prosaic English words. I like that about King's Field. It's just economical. No nonsense.
« Last Edit: July 19, 2018, 06:00:59 pm by Holy_Diver »

Offline Holy_Diver

  • Holy Diver
  • Archmage of Light
  • *****
  • Posts: 2280
  • This account won't read/reply to Private Messages
Re: Modding Expeditions (KF)
« Reply #38 on: July 20, 2018, 11:57:53 am »
Quote
typedef struct {
   char Unknown;
   char Unknown;
   char Unknown;
   char Unknown;
   char Unknown;
   char TileMeshIndex;
   char TileHeight;
   char TileRotation;
   char CollisionMesh;
   char LightValue;
} Tile;
The unknown values don't appear to do anything, I think two of them change how the tile is rendered, and either one or two of them are some form of packet ID for the tile. I'm writing up that reader now to see if we can get more information, since MO files are currently taking too much of my focus from the other aspects.

I almost missed this reply :sweatdrop:

It's important to get the CollisionMesh meshes. SOM calls these MHM. Though, most of the MHM files that come with SOM are just lazily copies of the MSM mesh, that is the mesh you see.  It's not absolutely essential, but unless they never turn up, it's worth the effort to curate them along with the tiles themselves. What is LightValue? Does it darken the mesh? It's a little odd... since it's applied to every tile. Is it a light source?

Offline TheStolenBattenberg

  • Capricorn Crusher
  • **
  • Posts: 192
Re: Modding Expeditions (KF)
« Reply #39 on: July 20, 2018, 01:20:14 pm »
Quote
It's important to get the CollisionMesh meshes. SOM calls these MHM. Though, most of the MHM files that come with SOM are just lazily copies of the MSM mesh, that is the mesh you see.  It's not absolutely essential, but unless they never turn up, it's worth the effort to curate them along with the tiles themselves. What is LightValue? Does it darken the mesh? It's a little odd... since it's applied to every tile. Is it a light source?

I think the collision meshes are just simplified versions of the tiles, it's just it can reference different tiles to use as the mesh. Such as the bumpy ice or rock in some areas, which just uses regular wall collisions. Either that, or some of the duplicate tiles may have been collision meshes for them.

Ah, I think there has been a mis-understanding about the tile data; the entire top section of the files (10 * 16384 bytes) is made up of actual grid data of the map.  It just points to the meshes and draws them according to a 2D array. This is why the light data can be different for each tile.
Ashes to ashes, Dust to dust...
Honor to glory; And iron to rust.
Hate to bloodshed, From rise to fall.
If I never have to die; Am I alive at all?