Author Topic: Help me. How the heck do i make individual files load ?  (Read 7407 times)

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Aali and 7h can load individual files from your hd outside of the archives. At the moment my mod manager is sleek and simple but it really could benefit from this feature. Without hooks I've managed to load the archives from new locations but i do not understand in any way shape or form how id make ff7 locate say aaaa.hrc on my hd instead of out of char.lgp. in fact im not even sure if ff7 loads all the files contained within to memory. It seems to? Are 3rd party dll hooks the only way of doing this or can i rewriteva ff7 function or two. I'd prefer the latter since 7h is chocabloc with 3rd party dlls.

My own dll can intercept functions if need be - but at the moment, all I've managed to do is locate and change path at the memory location the actual archives are loaded.  The functions related to that are a complete mystery to me.
« Last Edit: 2018-02-21 12:05:00 by DLPB »

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Help me. How the heck do i make individual files load ?
« Reply #1 on: 2018-02-21 13:22:27 »
Ugh. I've been wondering this exact thing for a long time. Aali's driver intercepts the archive loading routines and replaces game files with whatever it finds in specified directories. At least that's the way I remember it working. It's probably something more complex than that. I don't even know if the entire lgp archive structure is known. I've looked at it several times over the years and I still can't make heads-or-tails out of how it knows which file to pull.

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #2 on: 2018-02-21 13:25:37 »
The source for 7H is online and you can see from that that it'#s doing some sort of lgp lzs decoding too.  But i don't know C.  And to be frank, I fucking hate C.  I hate it with a passion.  Coming from Delphi to that makes me want to weep for the world.

JWP knows his stuff when it comes to this kind of thing.  Would love to see how it's done.

I can load different archives from anywhere I like by pushing a new path into a loading function.  From there I assume that the files are read to memory.  It's all easy with source, of course... but with asm it's beyond me.  And I think 7H and aali are diverting calls at the api level - not just rewriting functions.

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #3 on: 2018-02-22 23:03:56 »
Code: [Select]
FF7's "is_lib.cpp"
If you carefully read the previous posts, you may have notice some function calls commented with is_lib:; these functions belong to the is_lib module which performs the read operations on .lgp files (i.e archives).

The access to an archive is basically done with the next calls:
C_00675511; "opens" the archive file, and associate it with and Id (must be below 0x12); subsequent calls will use this Id only.
C_006759D2; allows to get the starting offset of an item (identified by name) in an opened archive (identified by its Id); since the caller uses this offset only as a parameter to subsequent calls, it maybe easier to consider this function as an "opener" and the offset as a "handle".
C_006762EA; returns the size of an entry (identified by its "handle") inside an opened archive.
C_0067633E; loads an entry into a buffer provided by the caller.
C_00675F1D; "closes" an archive
C_00676064; cleans the module, i.e closes all opened archives


The function I am changing pushes to is at 00675511.  Aali is hooking at 006759D2 to load individual files and handle it all.

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #4 on: 2018-02-22 23:42:31 »
 WM module for example pushes files at 75938C. 

Might be that the files need to be loaded into memory and pointers adjusted.
« Last Edit: 2018-02-23 03:18:01 by DLPB »

Maki

  • 0xBAADF00D
  • *
  • Posts: 621
  • 0xCCCCCCCC
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #5 on: 2018-02-23 13:07:47 »
Remember that you can do majority of things via simple C functions- fopen, fread, ftell.
Check FF7 imports to see what you can do.

I'm not at FF7 at all, but normally try to look for a code cave to input your asm code. Example as you wrote WM module stores file at 0x75938C, so try to break at C_00675511 and find the pointer to this location. This might be possibly an argument that gets passed every time. Note this pointer to code cave uint and get an filename from C_006759D2.
Now using sprintf import build a filepath to your working directory (thankfully the path is relative, so no need to deal with working directory grabbing)- if fopen returns -1 to EAX it means file doesn't exists (normally) so do CMP EAX, 0xFFFFFFFF and JE NormalFF7OpeningRoutine back to C_006759D2. If not, then fread by he count to buffer location read from the breakpoint and... return to all the way back up to original caller. Sorry I can't help you more... :/

But i don't know C.  And to be frank, I fucking hate C.  I hate it with a passion. 

« Last Edit: 2018-02-23 13:13:42 by Maki »

nfitc1

  • *
  • Posts: 3011
  • I just don't know what went wrong.
    • View Profile
    • WM/PrC Blog
Re: Help me. How the heck do i make individual files load ?
« Reply #6 on: 2018-02-23 16:01:10 »
C can do virtually ANYTHING because of how close to the asm you can get, but there's almost no simple way to do anything in C because you have to manually keep track of memory management and garbage collection. :)

Aali

  • *
  • Posts: 1196
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #7 on: 2018-02-23 21:56:47 »
You might find this interesting: https://github.com/Aali132/ff7_opengl

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #8 on: 2018-02-23 21:59:43 »
You might find this interesting: https://github.com/Aali132/ff7_opengl


Yeah, just a bit........

:P 

Thanks!!

Maybe it's time for me to learn C.....
« Last Edit: 2018-02-23 22:17:40 by DLPB »

obesebear

  • *
  • Posts: 1389
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #9 on: 2018-02-23 22:19:03 »
You might find this interesting: https://github.com/Aali132/ff7_opengl
Thanks for this. Does this mean you're done for the foreseeable future?

Aali

  • *
  • Posts: 1196
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #10 on: 2018-02-23 22:26:26 »
If it wasn't obvious to anyone, I've been 'done' for a while now. I read the odd post in this forum if it catches my eye but thats about it ???

DLPB_

  • Banned
  • *
  • Posts: 11006
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #11 on: 2018-02-23 23:05:08 »
If it wasn't obvious to anyone, I've been 'done' for a while now. I read the odd post in this forum if it catches my eye but thats about it ???

I've made a full replacement for the audio module, but I code in Delphi. I'm probably going to have to learn C and move my code across... but I am sure NFITC1 and a few others here will join me in making your driver even better. This is going to be a big help and conflicts with your code will be avoided too.

luksy

  • *
  • Posts: 375
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #12 on: 2018-03-04 10:43:05 »
Thanks for the code aali.

I made a few teensy changes to get it running on win 10 with the latest versions of glew, libpng, and zlib, I'll try and set up a fork at some point if others want to poke around. Currently trying to compile against win 7 for DLPB as the win 10 version crashes.

Mcindus

  • *
  • Posts: 929
  • Artist, Modder, Musician.
    • View Profile
    • Lunatic Pandora
Re: Help me. How the heck do i make individual files load ?
« Reply #13 on: 2018-03-05 19:41:16 »
Holy shnikies.  He posted the source?!  o.O  woohoo!!!  Maybe we'll be able to get the FF8 mods paths set up so we don't have to depend on Tonberry anymore!  (Tonberry's great and all... but it's a little 'hackish' and causes WAYY too much VRAM to be used.)

p.s.  - Thank you Aali!!

luksy

  • *
  • Posts: 375
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #14 on: 2018-03-06 05:09:26 »
Here's a fork with a few small fixes, confirmed working

https://github.com/ser-pounce/ff7_opengl

I haven't included a build config yet or include dependencies, will get round to it.

TrueOdin

  • *
  • Posts: 49
    • View Profile
Re: Help me. How the heck do i make individual files load ?
« Reply #15 on: 2019-11-02 16:09:19 »
Hi,

I think I'm a bit late into the party, but is it possible to ask for the build config you used to verify the source was working? I'm trying to build this code myself but with no success ( I'm able to get mostly everything running but hooks via Win32 API, which makes mod files impossible to be loaded ).

Thank you in advance.