JACoders / OpenJK

Community effort to maintain and improve Jedi Academy (SP & MP) + Jedi Outcast (SP only) released by Raven Software
GNU General Public License v2.0
2.03k stars 614 forks source link

Add new syscalls to check for engine type #608

Closed zig-for closed 9 years ago

zig-for commented 9 years ago

Hi, Subaru here. In some cases (patching the engine at runtime, mainly) it is useful to know what engine we are running (mostly if it is retail or not, but there are other instances, too).

I'd like to add TRAP_GETENGINE and TRAP_GETENGINEVERSION to the list of syscalls, replacing TRAP_TESTPRINTFLOAT and TRAP_TESTPRINTINT which do nothing.

trap_GetEngine would return a const char* representing the engine name ("OpenJK" in this case, "jaMME" for jamme, something else for thoughtful people who fork and pay attention). On baseJKA if it is called it will return null, so no issue there.

trap_GetEngineVersion would return a string version that is up to the engine maker (semantic versioning would be preferred).

Why not add new traps to the end? Well, in base it will cause needless errors and returns an ugly -1.

In any case, I have no problem with creating a patch to do this, but I wanted to make sure that the work would be accepted before I did it.

Exmirai commented 9 years ago

eeeem, there is another way to check it, if engine uses new api (not syscalls ) then its ojk, if it use syscalls then jamp.

zig-for commented 9 years ago

What other api? How can I check for it?

zig-for commented 9 years ago

Context: I'm running in mod code, linked to the original engine.

Exmirai commented 9 years ago

if you are querying modification using vmMain function ( cg/g_main.c ) then, it uses legacy api ( jamp ) . if you are querying modification using GetModuleAPI function, then it uses new api (OpenJK ).


int enginetype = 0; /// Define it somewhere

Q_EXPORT gameExport_t* QDECL GetModuleAPI( int apiVersion, gameImport_t *import ) { //// If Module API ( OpenJK )
   .....
   .....
 enginetype = 1; //OpenJK
}

(or)

Q_EXPORT intptr_t vmMain( int command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4,
    intptr_t arg5, intptr_t arg6, intptr_t arg7, intptr_t arg8, intptr_t arg9, intptr_t arg10, intptr_t arg11 ) {  /// If vmMain ( JaMP)
   .....
   .....
enginetype = 2; //JaMP
}
eezstreet commented 9 years ago

Just check the "version" cvar. If it's the same as baseJKA, then you know you're working with base.

Date: Sat, 3 Jan 2015 18:08:34 -0800 From: notifications@github.com To: OpenJK@noreply.github.com Subject: Re: [OpenJK] Add new syscalls to check for engine type (#608)

if you are querying modification using vmMain function ( cg/g_main.c ) then, it uses legacy api ( jamp ) . if you are querying modification using GetModuleAPI function, then it uses new api (OpenJK ).

int enginetype = 0; /// Define it somewhere

Q_EXPORT gameExport_t* QDECL GetModuleAPI( int apiVersion, gameImport_t *import ) { //// If Module API ( OpenJK ) ..... ..... enginetype = 1; //OpenJK }

(or)

Q_EXPORT intptr_t vmMain( int command, intptr_t arg0, intptr_t arg1, intptr_t arg2, intptr_t arg3, intptr_t arg4, intptr_t arg5, intptr_t arg6, intptr_t arg7, intptr_t arg8, intptr_t arg9, intptr_t arg10, intptr_t arg11 ) { /// If vmMain ( JaMP) ..... ..... enginetype = 2; //JaMP }

— Reply to this email directly or view it on GitHub.

                  =
ensiform commented 9 years ago

Basically what eezstreet said.

If dllEntry or vmMain are accessed, then its an older engine. Or if GetModuleAPI is accessed, then its OpenJK.

The newer API also has version numbers so you can bump those to change the API to add new func pointers.

zig-for commented 9 years ago

Did not know about the version cvar, thanks. That is exactly what I wanted.

zig-for commented 9 years ago

Ummm

zig-for commented 9 years ago

Can we make that say openJK?

Razish commented 9 years ago

No, for compatibility issues.

Instead of relying on the version cvar or an engine function that may or may not exist, it is more reliable to do a checksum of the engine in memory to know for sure that the code you're trying to patch is the same as base.

zig-for commented 9 years ago

It was going to be in addition to checking some bytes in memory. What kind of compatibility problems would be caused by changing that cvar?

ensiform commented 9 years ago

Some older tools like the all seeing eye break and you won't see servers if it doesn't say JAmp: v1.0.1.0

zig-for commented 9 years ago

Can we tack on [OpenJK] at the end? that shouldn't break anything.

ensiform commented 9 years ago

Why do you need it?

Check the year. As is done here: https://github.com/JACoders/OpenJK/blob/master/codemp/ui/ui_main.c#L4340-L4342

xycaleth commented 9 years ago

@A-t48 Can we close this issue now? I think the issue's been solved now.