Jump to content


Photo

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


4 replies to this topic

#1 Daxtreme

Daxtreme
  • Members
  • 118 posts
  • Gender:Not Telling
  • Location:Quebec

Posted 27 February 2018 - 09:04 PM

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, 27 February 2018 - 09:05 PM.


#2 Mike1072

Mike1072
  • Gibberling Poobah
  • 2428 posts
  • Gender:Male
  • Location:Canada

Posted 27 February 2018 - 10:54 PM

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


#3 Daxtreme

Daxtreme
  • Members
  • 118 posts
  • Gender:Not Telling
  • Location:Quebec

Posted 27 February 2018 - 11:12 PM

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, 27 February 2018 - 11:13 PM.


#4 Mike1072

Mike1072
  • Gibberling Poobah
  • 2428 posts
  • Gender:Male
  • Location:Canada

Posted 28 February 2018 - 01:47 AM

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


#5 Daxtreme

Daxtreme
  • Members
  • 118 posts
  • Gender:Not Telling
  • Location:Quebec

Posted 28 February 2018 - 08:11 AM

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, 28 February 2018 - 04:25 PM.




Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users