Hooks

A Forum dedicated to the Suggestion, Creation and Editing of XWA Dynamic Link Library Files

Moderator: JeremyaFr

Post Reply

Re: Hooks

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Tue Jan 16, 2018 1:21 pm

Hi Bman,
Bman wrote: 1) Is the ship category check based on the data within the .exe, or is it read directly from the shiplist.txt file ?
The ship category is read in the exe.
Bman wrote: 2) Does the mesh type and WP (laser hardpoint) type have any bearing on this ?
The mesh type and WP have no incidence on the decharge rate.
Bman wrote: 3) Can weapon sequence be changed to a number greater than 4 ?
The weapon sequence is set by the exe.
Bman wrote: 4) Finally, is it possible if could you implement the above unlimited ammo offset through an optional .cfg .lst, or .txt file like xwa_hook_main.cfg that is processed at runtime where for example... Offset 90A5c = 1 means unlimited, else = 0 means default status ?
I can create a hook to set the decharge rate based on the model index. The decharge rate would be read from a txt file created next to the opt file. If needed, the recharge rate could also be based on the weapon type. If a such file is not present, default values would be used.
The recharge rate could be set the same manner.

By default, the recharge rate is controlled as this:

Code: Select all

if the craft is TieFighter or TieBomber, the recharge rate is 3 * PresetLaser,
else the recharge rate is 2 * PresetLaser.
The value could be read from a txt file. It would be based on the model index and maybe the weapon type.

Bman
Lieutenant Commander
Posts: 1167
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Fri Jan 19, 2018 5:39 am

Awesome! Thanks.
W-I-P: TFTC, MC Viscount Cr., ISD-II Avenger, NL-1 Platform, Ton-Falk Esc. Cr., & Misc.

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Mon Jan 22, 2018 5:26 pm

Hello,

I've updated xwa_hook_mission_objects.
You can now define a gunner opt based on the player opt.

Suppose that the player craft is "FlightModels\[Player].opt".

The possible involved files are:
- "FlightModels\[Player]Gunner.opt"
- "FlightModels\CorellianTransportGunner.opt"

To define a custom gunner opt, you can either use the "Objects.txt" file to replace the "CorellianTransportGunner.opt" file or use a "[Player]Gunner.opt" file.

Please redownload xwa_hook_mission_objects.zip

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Mon Jan 22, 2018 7:48 pm

Not sure I know what you mean by

- "FlightModels[Player]Gunner.opt"

By "Player" do you mean like in the pliot file so the opt would be called say DSUCPGunner.opt or if you have a custom opt, say YT-1760.opt the gunner opt (if it existed) would be called YT-1760Gunner.opt?

And if there wasn't a YT-1760Gunner.opt the game would automatically use the CorellianTransportGunner.opt instead?

Just trying to get my head around the "Player" bit :D

The next bit I understand :)
To define a custom gunner opt, you can either use the "Objects.txt" file to replace the "CorellianTransportGunner.opt" file or use a "[Player]Gunner.opt" file.
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Mon Jan 22, 2018 7:59 pm

[Player] designates the player opt.

If the player opt is YT-1760.opt, then the gunner opt will be YT-1760Gunner.opt. If this file doesn't exist, CorellianTransportGunner.opt will be used.

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Mon Jan 22, 2018 8:07 pm

Ok got you :) cheers
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Mon Jan 22, 2018 8:58 pm

I've found a bug in xwa_hook_opt_limit.
Please redownload xwa_hook_opt_limit.zip

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Mon Jan 22, 2018 9:12 pm

Ok thanks :D
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sun Jan 28, 2018 4:15 pm

Hello,
Here is a new hook: xwa_hook_weapon_rate.

This hook permits to define weapon decharge and recharge rates for any craft.

Suppose that the craft is "FlightModels\[Model].opt".

To define the decharge and recharge rates, create a file named "FlightModels\[Model]WeaponRate.txt".
The format is:
DechargeRate = decharge value
RechargeRate = recharge value

If the file does not exist, default values are used.

By default, the decharge rate is controlled as this:

Code: Select all

if the ship category is Starfighter,
  if the craft is TieFighter or TieBomber, the decharge rate is 3,
  else the decharge rate is 4.
else
  if the weapon sequence is < 4, the decharge rate is 3,
  else there is no decharge.
By default, the recharge rate is controlled as this:

Code: Select all

if the craft is TieFighter or TieBomber, the recharge rate is 3 * PresetLaser,
else the recharge rate is 2 * PresetLaser.
Download link:
xwa_hook_weapon_rate.zip

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Sun Jan 28, 2018 7:31 pm

Thanks Jeremy :)

Quick question, what about the other craft like

Shuttle/Light Transport
Utility Craft
Container
Freighter/Heavy Transport
Starship
Station
Weapon emplacement (probably not applicable)
Satellite/Buoy (probably not applicable)

What would be the Recharge and Decharge rates for these craft?

Or does this Hook only apply to Starfighters?
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sun Jan 28, 2018 7:40 pm

For these crafts, the default decharge rate will be 3 and the default recharge rate will be 2.

Drinkinmiester
Cadet 1st Class
Posts: 136
Joined: Sun Nov 09, 2008 9:37 pm

Post by Drinkinmiester » Sun Mar 18, 2018 9:12 pm

So reading about this and, I'm trying to figure out how to use this to switch to different opts in a mission. I want to check and see if I'm getting this right. When I want to replace an opt in missions do I need both a "[MissionDir]\[Mission]_Objects.txt" for each mission as well as "FlightModels\Objects.txt"? Or just a "[MissionDir]\[Mission]_Objects.txt" for each instance I want to replace? Also I assume that the lines in the "[MissionDir]\[Mission]_Objects.txt" would be the same format as in the sample "objects.txt" included in the download, correct? Am I way off? Does somebody have an example that they've made that they can share to ilustrate how this is put into practice?

User avatar
Driftwood
Admiral (Moderator)
Posts: 2174
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Mon Mar 19, 2018 1:44 am

If it's in a specific mission you only need the MissionName_Objects.txt

Here's an example from one of DTM's missions.

1b9m1_Reunion_Objects.txt

Code: Select all

FlightModels\ContainerBrick.opt = FlightModels\Naboo_26Km.opt
FlightModels\ContainerHexBox.opt = FlightModels\Cielo_Notte.opt
FlightModels\ContainerTube.opt = FlightModels\TheedCity_26Km.opt
1b9m1_Reunion_HangarObjects.txt

Code: Select all

FlightModels\Ywing.opt = FlightModels\Blank.opt
FlightModels\Xwing.opt = FlightModels\Blank.opt
FlightModels\NabooN1L.opt = FlightModels\NabooN1LExterior.opt
FlightModels\Bwing.opt = FlightModels\Blank.opt
FlightModels\shuttle.opt = FlightModels\Blank.opt
FlightModels\HangarCrane.opt = FlightModels\Blank.opt
FlightModels\HangarDroid.opt = FlightModels\Blank.opt
FlightModels\HangarDroid2.OPT = FlightModels\Blank.opt
FlightModels\HangarGenerator.opt = FlightModels\Blank.opt
FlightModels\HangarMonitor.opt = FlightModels\Blank.opt
FlightModels\HangarRoofCrane.opt = FlightModels\Blank.opt
FlightModels\HangarWorkStand.opt = FlightModels\Blank.opt

Drinkinmiester
Cadet 1st Class
Posts: 136
Joined: Sun Nov 09, 2008 9:37 pm

Post by Drinkinmiester » Mon Mar 19, 2018 5:55 am

Thank you, I have used this info to free up the platform slots as suggested by dtm

Bman
Lieutenant Commander
Posts: 1167
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Sat Apr 14, 2018 10:33 pm

Hello, Jeremy just discovered a wonderful way to stop "Gun-Turret" meshes from randomly rotating when an enemy craft is not present. For example, on a number of non-flyable starships and stations you often see the meshes spinning and randomly rotating which looks silly in-game and not realistic. No more. Now those meshes can remain still and then resume moving/targeting enemy craft when within firing range.

Per Jeremy: "The code that controls the gun turret rotation speed is situated in function L00401880 at offset 1553 (:00402153). It looks like this:

Code: Select all


if( s_pXwaCurrentCraft->WeaponRacks[weaponIndex].ObjectIndex != -1 )
{
  the turret is oriented towards the targetted craft
}
else
{
  if( ( s_pXwaCurrentCraft->MeshRotationAngles[meshIndex] & 0x01 ) != 0 )
    s_pXwaCurrentCraft->MeshRotationAngles[meshIndex] += 0x04;
  else
    s_pXwaCurrentCraft->MeshRotationAngles[meshIndex] -= 0x04;

  if( XwaRandom() < 0x0600 )
  {
    s_pXwaCurrentCraft->MeshRotationAngles[meshIndex] ^= 0x01;
  }
}
To disable the rotation when there is no targetted craft, you can apply this:

Code: Select all

At offset 1553, replace 8A843160020000 with EB2E9090909090.
"
I'm not sure if this also applies to all other types of crafts such as fighters, freighters, and stationary gun emplacements and so forth.
Jeremy can better clarify that. Also, I've asked him if maybe he could make this patch offset as a separate runtime .dll file or just add it to an existing .dll file to keep things easier to install. :-)

EDIT: Moderators, I'm not sure if this should be posted under the XWA.Exe Patches thread instead ? If so, please move. Thanks.
W-I-P: TFTC, MC Viscount Cr., ISD-II Avenger, NL-1 Platform, Ton-Falk Esc. Cr., & Misc.

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sun Apr 15, 2018 12:24 pm

Hello,
I've added this patch to XwaExePatcher.
I don't know if it applies to all types of crafts. It needs to be tested.

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Sat May 19, 2018 7:17 pm

Hello,
Here is a new hook: xwa_hook_mission_tie.

This hook permits to override the data of mission files.

Suppose that the mission is "[MissionDir]\[Mission].tie".
To override the mission data, create a file named "[MissionDir]\[Mission].txt".
The format is a line per replacement.
To replace the flight group markings, the format is: "fg", fg number, "markings", value.

example:

Code: Select all

fg, 0, markings, 2
This line sets the markings to 2 for the flight group 0.

Download link:
xwa_hook_mission_tie.zip

User avatar
Driftwood
Admiral (Moderator)
Posts: 2174
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sat May 19, 2018 8:15 pm

Nevermind, saw other thread.

Neat!

Gotta get that next opt ready so we can have updated hooks with that installer.

Bman
Lieutenant Commander
Posts: 1167
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Sun May 20, 2018 1:00 am

Hi Jeremy, when you say "FG number 0" I assume that means the first indexed FG in the list at the top of the AlliED screen of the given mission.tie file.

XW.png

For example, I'm assuming the following could be a possibility with the X-Wing.opt model texture maps on a single wing mesh... etc.

TEX000***0 = generic Red (actually the generic x-wing markings is similar to Red 3)
Texture1 = generic Gold
Texture2 = generic Blue
Texture3 = generic Green

Texture4 = Red Leader Red
Texture5 = Red Leader Gold
Texture6 = Red Leader Blue
Texture7 = Red Leader Green

Texture8 = Red2 Red
Texture9 = Red2 Gold
Texture10 = Red2 Blue
Texture11 = Red2 Green
.
.
.
Texture24 = Red6 (Porkins) Red
Texture25 = Red6 Gold
Texture26 = Red6 Blue
Texture27 = Red6 Green

XW2.png

So mission text file could be for example 1b7m3_BofYavin.txt containing:

Code: Select all

fg, 0, markings, 4  (Red Leader with Red markings)
fg, 1, markings, 8  (Red2 with Red markings)
fg, 2, markings, 12  (Red3 with Red markings)
fg, 3, markings, 16  (Red4 with Red markings)
fg, 4, markings, 20  (Red5 with Red markings)
fg, 5, markings, 24  (Red6 with Red markings)
fg, 6, markings, 2  (Generic with Blue markings)

What if any FG is a backdrop (i.e. referencing *.dat file vs. an *.opt file) ? Will it ignore/CTD ? Thanks.
You do not have the required permissions to view the files attached to this post.
Last edited by Bman on Sun May 20, 2018 2:59 am, edited 5 times in total.
W-I-P: TFTC, MC Viscount Cr., ISD-II Avenger, NL-1 Platform, Ton-Falk Esc. Cr., & Misc.

User avatar
Driftwood
Admiral (Moderator)
Posts: 2174
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sun May 20, 2018 1:05 am

I would assume 1, yes.

And 2, I would imagine just replace fg 0 with whatever the desired fg is. So second indexed fg is an creating let's say, so you'd set fg to 1.

Correct me if my reasoning is incorrect.

Modified the mission.txt file and added the documentation text from the readme.
\\*** Usage ***

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

\\To override the mission data, create a file named "[MissionDir]\[Mission].txt".
\\The format is a line per replacement.
\\To replace the flight group markings, the format is: "fg", fg number, "markings", value.
\\See "mission.txt".

\\Flight Group, FG Color number (0-127) IE: 0 = Red, 1 = Gold, 2 = Blue, 3 = Green, ect.

fg, 0, markings, 2
Hmmm... all of Darksaber's special X-Wing textures. And yet again, more ship options become available without costing valuable ship slots.

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Sun May 20, 2018 9:51 am

You do realise that the x-wings have different Astromechs? How do you suggest replacing those for each FG? You can't have a Mesh as a FG

Plus take the X-wing Exteriors

Red Leader 78 textures
Red 2 = 87 textures
Red 3 = 95 textures
Red 4 = 86 textures
Red 5 = 92 textures
Red 6 = 86 textures

Red 4 and 6 have a dark cockpit where as the other have a blue interior, but you would still have to have each as a different FG

They have different amount of textures, but to get each FG to show correctly you would have to go with the highest amount which is Red 3 at 95 and multiply that by 6 = 570 textures, yes I know some of those textures are not FG's, but can you see my point!

That's without the generic X-wing which you talking about adding

and that's just the Exterior opts

Also it's not as simple as extracting the textures from one X-wing and adding them to the another x-wing, the different textures need to be renumbered, otherwise you'll just over writing the first lot of textures.

If after all 570 textures where added to one opt, who is to say the craft wouldn't crash the game, then you've wasted countless hours sodding about trying to get something to work, which might not.

And like I said that just the exterior opt, the same would apply to the Cockpit and Base opts.

You might be able to do this with the generic x-wing to just add the different stripes to the wings but doing it for the other xwings is a no no.

The amount of interest in this game these days is so small now it's not worth all the sodding about.

If we had all these new bell and whistles years ago, I might have tried this with the xwings, but not now.
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
Driftwood
Admiral (Moderator)
Posts: 2174
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Sun May 20, 2018 2:39 pm

I was just thinking the generic X-Wings myself. Partisan, Krayt, the theme'd squadron ones with the squadron decals on the side. I've always wanted a CorSec X-Wing too, maybe I'll pursue that retexture in the long run myself, I dunno.

Though, I admit I'd be interested to see it done to the Red squadron X-Wings, maybe say an R2/R5 mashup on a single one, with two FG as a proof of concept, just to verify that it is or is not technically viable.

I share the sentiment about the lack of interest in the game, but I mostly work on this stuff because I enjoy it, and hopefully my son will be interested in playing it with me as years go on (and I can afford another computer to network to) and benefit from my/our efforts. I still have friends who still have an interest in XWA, but haven't got the time or matching schedules to allow us to blow stuff up together at the moment.

Bman
Lieutenant Commander
Posts: 1167
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Sun May 20, 2018 6:04 pm

I see now mate. More complex than I realized. This patch might come in handy for other models though.
W-I-P: TFTC, MC Viscount Cr., ISD-II Avenger, NL-1 Platform, Ton-Falk Esc. Cr., & Misc.

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Sun May 20, 2018 7:03 pm

I like the idea, but I don't see how that would work, as far as I know you can't control what mesh is visible depending on FG

If it was possible you would be able to have the Xwing, Awing, Bwing and Ywing if one package and just select which was visible by which Flghtgroup you selected

The Partisan, nearly every texture would have to be replaced for the FG, the same problem as I've have explained above

The Krayt Xwing are really old textures as are the squadron xwing with the logo on the side, the textures would have to be updated really.

The easiest and most possible would be to modify the generic xwing as you would be replacing/adding less textures, just the outer wing textures and the sides of the fuselage perhaps the Astromech, but the astromech would have to be the same mesh.

I'm still confuse as to how this new Mission Hook works though

If FG is the number of Flightgroups (As in the texture Flightgroups, and say we still have the standard 4 Red, Yellow Blue and Green) then the value would be either 1, 2, 3 or 4 correct? So what it the "Markings" value for?

If I'm wrong, could a better explanation be given please
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
JeremyaFr
XWAU Member
Posts: 3921
Joined: Mon Jan 18, 2010 5:52 pm
Contact:

Post by JeremyaFr » Mon May 21, 2018 3:50 pm

Hello,

The "fg" and "markings" values start with 0.

"fg, 0" refers to the first flight group in .tie file.
For backdrops, the marking value is ignored.

With the standard 4 Red, Yellow, Blue and Green, the marking value will be 0, 1, 2 or 3.

In AlliED,
the Red color refers to marking 0,
the Gold color refers to marking 1,
the Blue color refers to marking 2,
the Green color refers to marking 3,
others markings can't be selected.

Here is how the marking is overriden:

Code: Select all

int TieHook(int* params)
{
	const auto LoadMission = (int(*)(const char*))0x420300;
	const char* fileName = (const char*)params[0];

	if (LoadMission(fileName) == 0)
	{
		return 0;
	}

	std::string path = GetStringWithoutExtension(fileName);
	path.append(".txt");

	auto lines = GetFileListValues(path);

	if (lines.empty())
	{
		return 1;
	}

	for (const auto& line : lines)
	{
		if (line.size() < 4)
		{
			continue;
		}

		const auto& group = line[0];

		if (_stricmp(group.c_str(), "fg") == 0)
		{
			int fg = std::stoi(line[1]);

			if (fg < 0 || fg > 192)
			{
				continue;
			}

			const auto& element = line[2];
			int value = std::stoi(line[3]);

			if (_stricmp(element.c_str(), "markings") == 0)
			{
				s_XwaTieFlightGroups[fg].Markings = value;
			}
		}
	}

	return 1;
}

Post Reply