Permalink
Browse files

Miloch macro patches

  • Loading branch information...
Valerio Bigiani
Valerio Bigiani committed Apr 8, 2012
1 parent 70f9091 commit 411aea74052a9197852209dcc69a23ce1ac8f911
Showing with 65 additions and 46 deletions.
  1. +3 −2 README-WeiDU-Changes.txt
  2. +7 −2 src/tph/include/fj_are_struct.tpa
  3. +41 −37 src/tph/include/fj_cre_validity.tpa
  4. +14 −5 src/tph/include/g_macros.tpa
View
@@ -1,11 +1,12 @@
-Versione 232:
+Version 232:
* Fixed blah blah blah for the benefit of non-English speaking people.
* Fixed a stack overflow when using COPY_EXISTING_REGEXP and you have more
than ~60000 files between your override and key.
* Lowercase the file name of binaries on Linux.
* AUTO_EVAL_STRINGS adds an implicit EVALUATE_BUFFER in front of every patch
string (notably, when dealing with arrays or functions).
- * in LAUNCH_*_FUNCTION, RET num is shorthand for RET num = ~%num%~.
+ * In LAUNCH_*_FUNCTION, RET num is shorthand for RET num = ~%num%~.
+ * Fixes to this and that in the macros.
Version 231:
* Fixed a bug that caused DISABLE_FROM_KEY to delete random files instead
@@ -146,6 +146,11 @@ DEFINE_PATCH_FUNCTION fj_are_structure
fj_cre_strref7 = ` 0
fj_cre_strref8 = ` 0
fj_cre_strref9 = ` 0
+ fj_duration = 1000
+ fj_wander_distance = 1000
+ fj_mvmt_distance = 1000
+ fj_day_prob = 100
+ fj_night_prob = 100
// map notes
fj_note_strref = ` 0
@@ -642,8 +647,8 @@ PHP_EACH struct AS key => value BEGIN
WRITE_SHORT fj_return_offset + 0x78 fj_delay
WRITE_SHORT fj_return_offset + 0x7a fj_method
WRITE_LONG fj_return_offset + 0x7c fj_duration
- WRITE_SHORT fj_return_offset + 0x80 fj_wander_distance
- WRITE_SHORT fj_return_offset + 0x82 fj_mvmt_distance
+ WRITE_SHORT fj_return_offset + 0x80 fj_wander_dist_spawn
+ WRITE_SHORT fj_return_offset + 0x82 fj_mvmt_dist_spawn
WRITE_SHORT fj_return_offset + 0x84 fj_max_num
WRITE_SHORT fj_return_offset + 0x86 fj_enable
WRITE_LONG fj_return_offset + 0x88 fj_schedule
@@ -203,7 +203,7 @@ DEFINE_PATCH_FUNCTION ~FJ_CRE_REINDEX~ BEGIN
WRITE_ASCIIE off_0 ~%is%~
END ELSE BEGIN
FOR (i_0 = 0; i_0 < 0x4c; i_0 += 2) BEGIN
- WRITE_SHORT off_0 + i1 0xffff
+ WRITE_SHORT off_0 + i_0 0xffff
END
END
SOURCE_SIZE = off_0 + 0x50
@@ -273,55 +273,57 @@ DEFINE_PATCH_FUNCTION ~FJ_CRE_EFF_V2~ BEGIN
END
END
-DEFINE_PATCH_FUNCTION ~t-CRE_EFF_V1~ BEGIN
+DEFINE_PATCH_FUNCTION ~T-CRE_EFF_V1~ BEGIN
PATCH_IF BYTE_AT 0x33 != 0 BEGIN
WRITE_BYTE 0x33 0
READ_LONG 0x2c8 fc //Effects count
PATCH_IF fc > 0 BEGIN
+ nfc = fc
READ_LONG 0x2c4 fs //Effects offset
READ_ASCII fs fx (0x108 * fc)
DELETE_BYTES fs (0x108 * fc)
sz = 0 //Size to reduce
SPRINT rfx ~~
INNER_PATCH ~%fx%~ BEGIN
- FOR (i1 = 0; i1 < fc; i1 += 1) BEGIN
- READ_SHORT ((i1 * 0x108) + 0x08) pc //Opcode
- READ_BYTE ((i1 * 0x108) + 0x0c) tg //Target
- READ_BYTE ((i1 * 0x108) + 0x10) pw //Power
- READ_LONG ((i1 * 0x108) + 0x14) p1 //Parameter 1
- READ_LONG ((i1 * 0x108) + 0x18) p2 //Parameter 2
- READ_BYTE ((i1 * 0x108) + 0x1c) tm //Timing mode
- READ_LONG ((i1 * 0x108) + 0x20) dr //Duration
- READ_BYTE ((i1 * 0x108) + 0x24) b1 //Probability 1
- READ_BYTE ((i1 * 0x108) + 0x26) b2 //Probability 2
- READ_ASCII ((i1 * 0x108) + 0x28) rf //ResRef
- READ_LONG ((i1 * 0x108) + 0x30) dt //Dice thrown
- READ_LONG ((i1 * 0x108) + 0x34) dz //Die size
- READ_LONG ((i1 * 0x108) + 0x38) st //Save type
- READ_LONG ((i1 * 0x108) + 0x3c) sb //Save bonus
- READ_BYTE ((i1 * 0x108) + 0x54) dp //Dispellability
+ FOR (t_1 = 0; t_1 < fc; t_1 += 1) BEGIN
+ READ_LONG (t_1 * 0x108 + 0x08) pc //Opcode
+ READ_LONG (t_1 * 0x108 + 0x0c) tg //Target
+ READ_LONG (t_1 * 0x108 + 0x10) pw //Power
+ READ_LONG (t_1 * 0x108 + 0x14) p1 //Parameter 1
+ READ_LONG (t_1 * 0x108 + 0x18) p2 //Parameter 2
+ READ_SHORT (t_1 * 0x108 + 0x1c) tm //Timing mode
+ READ_LONG (t_1 * 0x108 + 0x20) dr //Duration
+ READ_SHORT (t_1 * 0x108 + 0x24) b1 //Probability 1
+ READ_SHORT (t_1 * 0x108 + 0x26) b2 //Probability 2
+ READ_ASCII (t_1 * 0x108 + 0x28) rf //ResRef
+ READ_LONG (t_1 * 0x108 + 0x30) dt //Dice thrown
+ READ_LONG (t_1 * 0x108 + 0x34) dz //Die size
+ READ_LONG (t_1 * 0x108 + 0x38) st //Save type
+ READ_LONG (t_1 * 0x108 + 0x3c) sb //Save bonus
+ READ_LONG (t_1 * 0x108 + 0x54) dp //Dispellability
INNER_PATCH_SAVE rfx ~%rfx%~ BEGIN
+ tln = STRING_LENGTH ~%rfx%~
PATCH_IF pc < 191 BEGIN //If a valid BG1 opcode
sz += 0xd8
- INSERT_BYTES ((i1 * 0x30) + 0x00) 0x30
- WRITE_SHORT ((i1 * 0x30) + 0x00) pc
- WRITE_BYTE ((i1 * 0x30) + 0x02) tg
- WRITE_BYTE ((i1 * 0x30) + 0x03) pw
- WRITE_LONG ((i1 * 0x30) + 0x04) p1
- WRITE_LONG ((i1 * 0x30) + 0x08) p2
- WRITE_BYTE ((i1 * 0x30) + 0x0c) tm
- WRITE_BYTE ((i1 * 0x30) + 0x0d) dp
- WRITE_LONG ((i1 * 0x30) + 0x0e) dr
- WRITE_BYTE ((i1 * 0x30) + 0x12) b1
- WRITE_BYTE ((i1 * 0x30) + 0x13) b2
- WRITE_ASCIIE ((i1 * 0x30) + 0x14) ~%rf%~
- WRITE_LONG ((i1 * 0x30) + 0x1c) dt
- WRITE_LONG ((i1 * 0x30) + 0x20) dz
- WRITE_LONG ((i1 * 0x30) + 0x24) st
- WRITE_LONG ((i1 * 0x30) + 0x28) sb
+ INSERT_BYTES (tln + 0x00) 0x30
+ WRITE_SHORT (tln + 0x00) pc
+ WRITE_BYTE (tln + 0x02) tg
+ WRITE_BYTE (tln + 0x03) pw
+ WRITE_LONG (tln + 0x04) p1
+ WRITE_LONG (tln + 0x08) p2
+ WRITE_BYTE (tln + 0x0c) tm
+ WRITE_BYTE (tln + 0x0d) dp
+ WRITE_LONG (tln + 0x0e) dr
+ WRITE_BYTE (tln + 0x12) b1
+ WRITE_BYTE (tln + 0x13) b2
+ WRITE_ASCIIE (tln + 0x14) ~%rf%~
+ WRITE_LONG (tln + 0x1c) dt
+ WRITE_LONG (tln + 0x20) dz
+ WRITE_LONG (tln + 0x24) st
+ WRITE_LONG (tln + 0x28) sb
END ELSE BEGIN
sz += 0x108
- fc -= 1
+ nfc = nfc - 1
END
END
END
@@ -330,9 +332,11 @@ DEFINE_PATCH_FUNCTION ~t-CRE_EFF_V1~ BEGIN
READ_LONG f1 f2
WRITE_LONG f1 ((f2 > fs) ? (f2 - sz) : (f2 < 0x2d4 ? 0x2d4 : f2))
END
- INSERT_BYTES fs (0x30 * fc)
+ PATCH_IF nfc > 0 BEGIN
+ INSERT_BYTES fs (0x30 * nfc)
WRITE_ASCIIE fs ~%rfx%~
- WRITE_LONG 0x2c8 fc //Update effects count
+ END
+ WRITE_LONG 0x2c8 nfc //Update effects count
SOURCE_SIZE -= sz
END
END
@@ -277,6 +277,11 @@
DEFINE_PATCH_MACRO ~ADD_ITEM_EQEFFECT~ BEGIN
PATCH_IF (BUFFER_LENGTH > 0x71) THEN BEGIN
+ PATCH_IF (~%SOURCE_EXT%~ STRING_EQUAL_CASE ~spl~ = 1) BEGIN
+ ___#hdr_size = 0x28
+ END ELSE BEGIN
+ ___#hdr_size = 0x38
+ END
READ_LONG 0x64 ___#abil_off
READ_SHORT 0x68 ___#abil_num
READ_LONG 0x6a ___#fx_off
@@ -307,10 +312,10 @@
//correcting 1st effect ___#index1es
FOR (___#index2 = 0 ; ___#index2 < ___#abil_num ; ___#index2 = ___#index2 + 1) BEGIN
- READ_SHORT (___#abil_off + ___#index2 * 0x38 + 0x20) ___#1effect_index
+ READ_SHORT (___#abil_off + ___#index2 * ___#hdr_size + 0x20) ___#1effect_index
PATCH_IF (___#1effect_index > ___#eqfx_index) //if abilility after eq effects
OR ((___#1effect_index = ___#eqfx_index) AND (___#eqfx_num = 0)) BEGIN
- WRITE_SHORT (___#abil_off + ___#index2 * 0x38 + 0x20) (___#1effect_index + 1) //increase 1 effect ___#index1 by 1
+ WRITE_SHORT (___#abil_off + ___#index2 * ___#hdr_size + 0x20) (___#1effect_index + 1) //increase 1 effect ___#index1 by 1
END
END
//no offsets to correct
@@ -581,8 +586,8 @@
WRITE_LONG (___#fx_off + 0x4c) lowestafflvl
WRITE_LONG (___#fx_off + 0x50) highestafflvl
WRITE_LONG (___#fx_off + 0x54) resist_dispel
- WRITE_BYTE (___#fx_off + 0x58) parameter3
- WRITE_BYTE (___#fx_off + 0x59) parameter4
+ WRITE_LONG (___#fx_off + 0x58) parameter3
+ WRITE_LONG (___#fx_off + 0x5c) parameter4
WRITE_EVALUATED_ASCII (___#fx_off + 0x68) ~%vvcresource%~ #8
WRITE_EVALUATED_ASCII (___#fx_off + 0x70) ~%resource2%~ #8
WRITE_LONG (___#fx_off + 0x78) casterx
@@ -654,7 +659,11 @@
READ_LONG 0x2c8 ___#fx_num
SET ___#delta = 0
FOR (___#index1 = 0; ___#index1 < ___#fx_num; ___#index1 = ___#index1 + 1) BEGIN
- READ_LONG (___#fx_off + ___#index1 * (___#fx_flag = 1 ? 0x108 : 0x30) + (___#fx_flag = 1 ? 0x8 : 0x0)) ___#opcode
+ PATCH_IF ___#fx_flag = 0 BEGIN
+ READ_SHORT (___#fx_off + ___#index1 * 0x30) ___#opcode
+ END ELSE BEGIN
+ READ_LONG (___#fx_off + ___#index1 * 0x108 + 8) ___#opcode
+ END
PATCH_IF ((___#opcode = opcode_to_delete) OR (opcode_to_delete = (0 - 1))) BEGIN
DELETE_BYTES (___#fx_off + ___#index1 * (___#fx_flag = 1 ? 0x108 : 0x30)) ___#fx_flag = 1 ? 0x108 : 0x30
SET ___#delta = ___#delta + 1 //track deleted number

0 comments on commit 411aea7

Please sign in to comment.