Jump to content

READ_ cre name, then if it matches, change another cre name


Daxtreme

Recommended Posts

hey guys,

 

I'm still a beginner at weidu modding and I was wondering how I would go about reading a .cre file's string name, see if it matches, then if it does, change another cre file's string name?

 

Basically I'm making a small mod that has to check if another mod has changed the name of a cre file's name. If it did, then I change another cre file's name to match it.

 

I know how to write a cre's file, but not how to check it!

 

Here's what I have so far, the WRITE part. I change "mage18a" name to "Cowled Wizard"

        ACTION_IF FILE_EXISTS_IN_GAME ~mage18a.cre~ BEGIN
		COPY_EXISTING ~mage18a.cre~ ~override~
			LPF SANITIZE_CRE RET ok = ok END
			PATCH_IF ok BEGIN
				WRITE_LONG 0x0008 10006
				WRITE_LONG 0x000c 10007
			END
		BUT_ONLY
	END

I simply have no idea how to READ and put an IF statement along with it :p Like

 

If (NOT) ~cowenf2.cre~ NAME = 10006

 

THEN change ~mage18a.cre~ NAME to 10006 (I think I got that part right above)

 

Hopefully that makes any sense :p

Edited by Daxtreme
Link to comment

If you want the two names to match, I'd take whatever value exists in cowenf2 and write it to mage18a.

COPY_EXISTING ~cowenf2.cre~ ~override~
  READ_LONG 0x08 name
  READ_LONG 0x0c tooltip
  BUT_ONLY
 
COPY_EXISTING ~mage18a.cre~ ~override~
  WRITE_LONG 0x08 name
  WRITE_LONG 0x0c tooltip
  BUT_ONLY
Link to comment

no that's not quite it! I need to check if it was changed first.

 

If it hasn't been changed, do nothing! Only change the name of the other cre file if the first has been changed :)

 

But thanks, so READ_LONG 0x08 returns the string name (as numbers) of a cre? Awesome!

Edited by Daxtreme
Link to comment

If the string you are looking for is added by a mod, the strref will differ across installations, so you can't do a numerical comparison. You'd have to fetch the string with READ_STRREF instead and do a string comparison to see if the text matches.

 

If the string is part of the vanilla game, its strref number will always be the same, so you can just check if the number in the file matches the known value. This has a benefit in that it works regardless of the game's language.

 

To do a numeric comparison, you can use name == 123. The opposite would be name != 123.

 

To do a string comparison, you can use ~%name%~ STRING_EQUAL ~abc~. The opposite would be NOT ~%name%~ STRING_EQUAL ~abc~.

 

Throw it in a PATCH_IF or ACTION_IF depending on the context.

COPY_EXISTING ~cowenf2.cre~ ~override~
  READ_LONG 0x08 name
  READ_LONG 0x0c tooltip
  BUT_ONLY

ACTION_IF (name == 123) BEGIN
  COPY_EXISTING ~mage18a.cre~ ~override~
    WRITE_LONG 0x08 name
    WRITE_LONG 0x0c tooltip
    BUT_ONLY
END
Link to comment

Oh that's great! Since it's a vanilla string, that's what I'm gonna do!

 

Basically --

 

ACTION_IF NOT (name == 10006) BEGIN // Check if name has been changed from Vanilla name

COPY_EXISTING blablabla

 

I guess tooltip is the 2nd name field?

 

What do you mean PATCH_IF vs ACTION_IF? What's the difference?

 

Thanks a lot!

 

edit: Holy crap I just realized that I was using NearInfinity version....

 

1.32

 

That one was released in 2010!

 

Haha jeez, this is gonna be such a huge jump! Thanks to Roxanne for mentioning the Dialog Tree format in a help thread and me realizing I didn't have the tree view in question :p

 

EDIT2: Here's what I came up with, pretty sure it's correct:

	COPY_EXISTING ~cowenf2.cre~ ~override~
  		READ_LONG 0x08 name
  		READ_LONG 0x0c tooltip
  		BUT_ONLY
	
	ACTION_IF (name != 10006) BEGIN
  		COPY_EXISTING ~mage16c.cre~ ~override~
  			LPF SANITIZE_CRE RET ok = ok END
   			PATCH_IF ok BEGIN
				WRITE_LONG 0x0008 10006
				WRITE_LONG 0x000c 10007
			END
    	BUT_ONLY
	END

Thanks for your help! I think I'm gonna get the hang of this soon (I wrote some lua a few years back)

Edited by Daxtreme
Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...