Hooks

Need help editing the game? Check for help here!

Moderators: Darksaber, General_Trageton, Forceflow

Hooks

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Fri Sep 15, 2017 1:19 pm

This thread is made for a general discussion about the hooks.

A hook is a way to inject code into the exe. It enhances, adds a feature to, or fixes a problem with the game. Read the readme file inside the hook package for more informations about what the hook does.

You can download the hooks here:
https://onedrive.live.com/redir?resid=A ... 94FB%21116
The hooks are packaged in zip files. The filenames start with "xwa_hook_".

The source code of the hooks is here:
https://github.com/JeremyAnsel/xwa_hooks

To discuss the hooks, you can post here. Or to discuss about a specific hook, there may be a sticky thread in the Editing section.

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Fri Oct 20, 2017 2:35 pm

Hello,

Here is an "Hello World" sample to show how to create a hook.

The hook shows "Hello, World!" at the bottom of the game menu, before the version string.

The sample comes in 2 versions: a C++ version and a C# version.

C++ version:
link: https://github.com/JeremyAnsel/xwa_hook ... orld%20Cpp

The hook does this:

Code: Select all

int HelloWorldHook(int* params)
{
	const auto XwaGetFrontTxtString = (const char* (*)(int))0x55CB50;

	char* bufferPtr = (char*)0xABD680;
	const int bufferSize = 256;

	const int FrontTxt_STR_CONFIG_VERSION = 1168;

	strcpy_s(bufferPtr, bufferSize, "Hello, World! ");
	strcat_s(bufferPtr, bufferSize, XwaGetFrontTxtString(FrontTxt_STR_CONFIG_VERSION));
	strcat_s(bufferPtr, bufferSize, "2.02");

	return 0;
}
C# version:
link: https://github.com/JeremyAnsel/xwa_hook ... World%20Cs

The hook does this:

Code: Select all

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.LPStr)]
delegate string XwaGetFrontTxtStringDelegate(int index);

static XwaGetFrontTxtStringDelegate XwaGetFrontTxtString = (XwaGetFrontTxtStringDelegate)Marshal.GetDelegateForFunctionPointer(
    new IntPtr(0x55CB50), typeof(XwaGetFrontTxtStringDelegate));

public static int HelloWorldHook(IntPtr @params)
{
    IntPtr bufferPtr = new IntPtr(0xABD680);
    const int FrontTxt_STR_CONFIG_VERSION = 1168;

    byte[] message = Encoding.ASCII.GetBytes("Hello, World! \0");

    Marshal.Copy(message, 0, bufferPtr, message.Length);

    byte[] message2 = Encoding.ASCII.GetBytes(XwaGetFrontTxtString(FrontTxt_STR_CONFIG_VERSION) + "2.02\0");
    Marshal.Copy(message2, 0, IntPtr.Add(bufferPtr, message.Length - 1), message2.Length);

    return 0;
}

Bman
Ensign
Posts: 462
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Sat Nov 11, 2017 9:16 pm

Awesome! Thanks
W-I-P: ISD-II, XQ-1 Platform1, New Escort Carrier Hangar, & Misc.

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sun Dec 31, 2017 4:27 pm

Hello,

Here is a hook to replace mission objects.

Suppose that the mission is "[MissionDir]\[Mission].tie".

The possible involved files are:
- "[MissionDir]\[Mission]_Objects.txt"
- "FlightModels\Objects.txt"

To replace the objects, create a file named "[MissionDir]\[Mission]_Objects.txt".
The dll searches a "Objects.txt" file in this order (from first to last):
- "[MissionDir]\[Mission]_Objects.txt"
- "FlightModels\Objects.txt"
If a "Objects.txt" file doesn't exist, no model is replaced.
The format is a line per object: "FlightModels\ObjectA = FlightModels\NewObjA"

xwa_hook_mission_objects.zip

User avatar
DTM
Lieutenant
XWAU Member
Posts: 955
Joined: Tue Apr 22, 2003 11:01 pm
Contact:

Post by DTM » Sun Dec 31, 2017 5:37 pm

It's incredible, how many applications can this new hook have ...
Thank you!!!!!!!

MTD industries
WIPs: XWA campaign based on Rebels TV Show

User avatar
Darksaber

Fleet Admiral (Administrator)
Posts: 9247
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Sun Dec 31, 2017 7:39 pm

Another one jezz, you spoil us :D
Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

Bman
Ensign
Posts: 462
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Sun Dec 31, 2017 10:23 pm

Wonderful Jeremy! So this hook temporarily allows the flexibility of switching .opt files for specific flight mission(s).
How are you defining "objects"? Is it only stationary/non-flyable .opt models like cargo canisters and such things?
W-I-P: ISD-II, XQ-1 Platform1, New Escort Carrier Hangar, & Misc.

User avatar
Darksaber

Fleet Admiral (Administrator)
Posts: 9247
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Sun Dec 31, 2017 11:05 pm

Looks like you can replace any object i.e. opt

Looks like you can replace specific opts in a mission you would place the object.txt file in the missions Dir,
"[MissionDir][Mission]_Objects.txt" it would be rename to 1b0m1fw_Objects.txt say you want to replace Harlequin Station which is Platform1.opt with say a Star Destroyer, then you open the 1b0m1fw_Objects.txt and type
FlightModels$Platform1.opt = FlightModels$ImperialStarDestroyer.opt

(Bloody Forum) replacing the $ with a forward slash

If you want to replace an certain opt in ALL missions the Object.txt file is placed in the Flightmodels folder and is just named Object.txt

So if you had the same FlightModels$Platform1.opt = FlightModels$ImperialStarDestroyer.opt

(Bloody Forum replacing the $ with a forward slash)

All instances of the Platform1.opt would be replaced with the ImperialStarDestroyer.opt

but remember the replaced opts stats would remain the same as the craft it's replacing, so if you replace the Platform1.opt with the ImperialStarDestroyer.opt, the ImperialStarDestroyer.opt would still act as though it was still the Platform1.opt

Unless Jeremy's offset changes the stats for the replaced opt, which I doubt it would do, but I maybe wrong :)

Perhaps Jeremy can shed some light on this matter :)

Happy New Year :)
Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

Bman
Ensign
Posts: 462
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Sun Dec 31, 2017 11:58 pm

.
Last edited by Bman on Sat Jan 13, 2018 4:06 am, edited 1 time in total.
W-I-P: ISD-II, XQ-1 Platform1, New Escort Carrier Hangar, & Misc.

User avatar
DTM
Lieutenant
XWAU Member
Posts: 955
Joined: Tue Apr 22, 2003 11:01 pm
Contact:

Post by DTM » Mon Jan 01, 2018 12:27 am

Thanks to this hook it's possible to have many plantary scenarios using only one slot. That's brilliant!!! Also it is possible to introduce special FG colors to be used in special missions, or modified customezed crafts...it's a good solution to avoid vaste of empty slots! Other applications? Relic starships...many types of modular space stations, many types of shipyards...everything you can imagine without the limit of the empty slot...

Happy new year!!!!

MTD industries
WIPs: XWA campaign based on Rebels TV Show

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Mon Jan 01, 2018 11:06 am

The stats of the replaced crafts are not changed.

Bman
Ensign
Posts: 462
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Tue Jan 02, 2018 5:20 am

.
Last edited by Bman on Sat Jan 13, 2018 4:07 am, edited 1 time in total.
W-I-P: ISD-II, XQ-1 Platform1, New Escort Carrier Hangar, & Misc.

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Thu Jan 04, 2018 5:13 pm

Hello,

I've fixed a bug in the main hook.
Please redownload xwa_hook_main.zip

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Fri Jan 12, 2018 12:44 pm

Hello,

I have updated xwa_hook_mission_objects.
The craft turrets are no longer limited to CorellianTransport2, MilleniumFalcon2, and FamilyTransport. You can now enable turrets for any craft.

Note that the CorellianTransport2 stats need to be edited to disable the second turret (It has only one turret).

Please redownload xwa_hook_mission_objects.zip

User avatar
Darksaber

Fleet Admiral (Administrator)
Posts: 9247
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Fri Jan 12, 2018 1:39 pm

Lol I knew it :D

a bit of editing to do know

Thanks :D

EDIT: Found out a couple of things while testing, you will have to add a Gunner Hardpoint to your turret Mesh otherwise the Turret Gunner Tunnel Opt (Not sure what else to call it) will not show in game. Your still able to use a turret, but there will be NO visible Gunner Tunnel thingy :)

Plus the Turrets POV's have to be set to X=0, Y=250, Z=19 for the CorellianTransportGunner.opt, of course if you make your own Gunner Tunnel OPT the POVs might be different.
Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
Driftwood
Lieutenant Commander
XWAU Member
Posts: 1137
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sat Jan 13, 2018 3:42 am

How do you find the X/Y/X turret coordinates and the pod orientation X/Y and arc coordinates?

I'm debating starting up my escort shuttle cockpit again in what little free time I have, and I figure it couldn't hurt to do a turret for it either now that this hook exists. However, I need to figure out how to figure out positioning for the rear facing turret.

I just enabled the MUTR, but obviously the data exists already so I have no idea how everything is calculated. Though I do somewhat wonder if the turrets are indeed aligned the direction they should be. (will look into this later)

Y/W (B) is something else I'm pondering conceptually.

Edit:

Well, I've made a dummy (test) opt for the Y/W (B) using a modified exterior opt, since I figured it'd be the easiest way to give this a try.

Flightmodels folder has:

YwingB.opt
YwingBcockpit.opt
YwingBexterior.opt
YwingBgunner.opt

The technical details as I have come to find them:

Arc 1 controls up/down range of motion of turret 1
Arc 3 controls left/right range of motion of turret 1

Arc 2 controls up/down range of motion of turret 2
Arc 4 controls left/right range of motion of turret 2

Setting pod 1 (or 2) x/y orientation to 0/0 sets POV straight forward. I do not at this time have any other stats for the other cardinal directions.

The good:
Setting pod orientation X / Y to zero for the Y/W (B) is perfect for the forward facing default direction
Setting Gunner 1 coordinates to X 150, Y 65, and Z 0 is just right for gunner POV
Setting Arc 1 to 1200, and Arc 3 to 31000 is perfect ARC wise, though the climb on the turret is extremely limited since I'm trying to avoid clipping through the model on the turret depression side of things. It should be playable enough however.
Model wise it appears to need little modification besides removing hidden faces and the clone trooper in the turret. (see animation issue below)

The bad:
DO NOT GO BEYOND +/- 31000 on your arc range of motion! You will not be happy!
So far the gun animation doesn't work right, there's limited movement (almost no movement)it seems with the turret animation at this point, but then I've not modified the YwingBExteroir.opt (duplicated to be YwingBGunner.opt) beyond adding in 4x empire laser hardpoints thus far (which seem to do nothing as of yet). I imagine this has to do with the mesh assignments. So one issue graphically is that the gun turret doesn't pivot with the player camera at all.

I still can't for the life of me get the bloody turret to fire at all while controlling it, and I'm starting to wonder if that's because technically on the base opt itself it doesn't have a turret weapon technically. Still trying to figure this out.

I was originally testing this in skirmish mode as I was somewhat under the impression that it would reference the turret similarly to the way the game references the cockpit and exterior models. Apparently this doesn't seem to be the case and is still calling the default corellian transportgunner.opt. It would be great if this could be looked into and hopefully fixed so custom turrets can be used in skirmishes as well as custom missions.

Probably more of a DSUCP bug the other issue I noticed is that the Y/W (B) base opt in this version of DSUCP (before modifications in any way) the lasers/ions/missiles all come out between where the weapon hardpoints actually are. I imagine the weaponry tab needs some tweaking to work correctly.
Image
R.I.P RSF_Zjon1, RSF_Mac, RSF_Vasquez

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sat Jan 13, 2018 7:31 pm

# arc range
The arc range are short values. Values go from -32768 to 32767.

# custom gunner opt
You replace the gunner opt, you can either use the Objects txt file to replace the CorellianTransportGunner with a custom opt, either modify the craft stats to point the turret to a custom gunner opt instead of the CorellianTransportGunner (317). The second option requires an empty craft slot.

# working turret
If you replace the Outrider with the CorellianTransport2 (stats and opt), the turret works. You can inspect the opt to figure out how to make the turrets to work.

User avatar
Driftwood
Lieutenant Commander
XWAU Member
Posts: 1137
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sat Jan 13, 2018 8:25 pm

Okay well that turned out simple enough then.

I typed in 42 (YW/B) craft # in place of 317 in the turret 1 activation status and it called the correct opt in the flightmodels folder no problem when loading a skirmish mission by default.

Thanks Jeremya.

As for the YT2400 example, it already appears to work by default without changing any settings once I enabled the turret hook; that said, I'll take a look and see if I can figure out what you're referencing looking for.

Also, do you have any idea in regards to negative numbers vs positive in relation to turret functions? I'm kind of wondering if you can somehow restrict up/down left/right movement depending on whether or not the number is pos/neg.
Image
R.I.P RSF_Zjon1, RSF_Mac, RSF_Vasquez

JeremyaFr
Lieutenant JG
XWAU Member
Posts: 700
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sat Jan 13, 2018 8:34 pm

The YT-2400 turret doesn't work in the vanilla game. It works fine with the UCP.

User avatar
Driftwood
Lieutenant Commander
XWAU Member
Posts: 1137
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sat Jan 13, 2018 9:12 pm

Apparently the Y/W B opt as installed by DSUCP has no hardpoints on the opt. At all. Also apparently, the weapons were only defined in MXvTED, which would (could) explain why the lasers and missiles were firing from the center point.

After adding hardpoints the weapons are firing from where they are supposed to. However, while the AI fire turret works fine, the player controlled turret fires the pilot's lasers, and for some reason stops firing altogether after a while (not regenerating?).

One other oddity, is that unless the turret weapon is set to rebel/empire turbo-laser, it links with the primary/secondary weapons. (easy fix)

The turret animation also doesn't work at all it seems on the player craft at the moment - that is with the arcs set up the way I have them perhaps?

Edit: I can't figure the following issues.

1. The player controlled gun turret runs out of charge and just stops putting out shots. Period. I even put a "power regeneration" designated mesh like the YT1300 has in the XWAU version. Function wise this is the biggest problem I'm having since there's no point in having a player controlled turret that goes dead.
2. The player controlled gun turret is firing from the pilot's forward laser hardpoints, not the ones attached to the turret. Second biggest issue since it's not firing from the correct source, ie; the turret turbo-laser hardpoints. (But I can't figure out why)
3. The player turret animation is not following the camera and barely moves. (Not pretty, but minor issue that hopefully can be fixed)
4. When pushing auto/defensive fire (using (F) from the pilot's seat, the turret behaves correctly. (Fires red lasers in skirmish - non-issue)
5. Player craft turret animation doesn't function in external view. (Not sure it does by default anyways)

Issues 1-2 are the priority to figure out at the moment as far as I am concerned.
Last edited by Driftwood on Sat Jan 13, 2018 9:41 pm, edited 2 times in total.
Image
R.I.P RSF_Zjon1, RSF_Mac, RSF_Vasquez

User avatar
Darksaber

Fleet Admiral (Administrator)
Posts: 9247
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Sat Jan 13, 2018 9:32 pm

The Y/W B Base opt has since been fixed with all hardpoints accounted for, not sure why they where missing ?? A new version of the DSUCP is in the works, but I won't be adding or chaning any opts to account for the Turret info, I have removed the 2nd turret info from the YT1300.

If you trying to get a version of the Y/W B turret working like the Gunner turret you need to study how the Gunner turret works, what order the meshes are in, how the meshes rotates, what the meshes are named, are any hardpoints added and so on, you can't just bash together a gunner opt and expect it to work the same as the gunner turret.

I've never really looked at the gunner turret so I know little about it, there has never been any necessity to do so before now, that is. :)
Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
Driftwood
Lieutenant Commander
XWAU Member
Posts: 1137
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sat Jan 13, 2018 9:51 pm

Yeah, I have no idea why the hardpoints were missing, I was surprised when I opened up the opt myself.

I've been studying the gunner opt, the YT1300 base opt, and the Y/W B opts pretty much all last evening before bed, and part of this afternoon.

I realize that gunner opt =/= custom opt will not likely work 1:1. At this point I'm just trying to figure something out for proof of concept using an already existing opt (my modeling/texturing skills are limited) as a basis for said concept. Most of the work has been thus far in figuring out the function within MXvTED via trial by error.

My theory with the animation part of things is likely due to the fact that the arcs range of motion are more limited in the up/down range than the YT1300's, and I believe that most of the animation from the original turret is tied to the up/down axis, rather than the left/right axis. There may not be much of a fix for that if that's the case, as far as I can see. Either that, or I just haven't imagined up a solution yet and am thinking too far inside the box.

At the moment, I'm double checking my order for the meshes compared to the gunner opt.

But honestly, I'd rather find a fix for the lasers firing from the wrong hardpoints and then suddenly going dead for no obvious reason.

Functionality is more important to me at the moment than aesthetics since there are likely still going to be certain engine limitations to turret functionality regarding animations.

EDIT: I've changed around the meshes to match the gunner opt, and there's zero impact in animation functionality.

Still unable to figure out why turret lasers are firing from the wrong hardpoints, and won't recharge.
Image
R.I.P RSF_Zjon1, RSF_Mac, RSF_Vasquez

User avatar
Driftwood
Lieutenant Commander
XWAU Member
Posts: 1137
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sat Jan 13, 2018 11:02 pm

Okay, I'm officially entirely stuck.

1. Still fires from the wrong hardpoints for no obvious reason.
2. Runs out of laser charge and won't regen.

Can't figure out how to resolve either issue. Kind of fixed #1, but then the laser's stopped firing at all while controlling the turret for no obvious reason. So I reverted back.

This is starting to annoy me.
Image
R.I.P RSF_Zjon1, RSF_Mac, RSF_Vasquez

User avatar
Darksaber

Fleet Admiral (Administrator)
Posts: 9247
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Sun Jan 14, 2018 12:20 am

Have you tried setting it as a shuttle?
Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
Driftwood
Lieutenant Commander
XWAU Member
Posts: 1137
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sun Jan 14, 2018 1:27 am

Well, apparently that does in fact make the turret controlled weapons unlimited charge. But not an ideal fix given it requires changing the ship classification. Still the issue of firing from the wrong hardpoints remains, still no idea why. Doesn't make a lick of sense. Getting to where I want to scrap my efforts and move onto something else.

I did notice the superrebel lasers firing from the wingtip lasers on the Moldy Crow also when manually firing, though the superrebel lasers did fire from the turret as they are supposed to with auto-fire. I'm starting to wonder if there's a general bug with the engine. However, with that said I have not seen this issue with the YT1300, YT2000, YT2400 or Falcon models, so I'm scratching my head on that one. It's not consistent.

It's strange though, turret auto fire works fine when classed as a fighter, but the manual control doesn't work right both on what hardpoints fire, doesn't have unlimited charge (or regenerate when recharging lasers) when assigned to a fighter designated ship.

Am I overthinking this?
Image
R.I.P RSF_Zjon1, RSF_Mac, RSF_Vasquez

Post Reply