Pokemon Center | 口袋中心 以口袋妖怪为主题并带有其他动漫游戏的讨论

 找回密码
 加入口袋中心
搜索
查看: 2001|回复: 6

用C语言重构脚本中的cmdA6

[复制链接]

3344

回帖

3

现金

484

勋章券

超级版主

Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26

积分
21852
QQ

时光印记Lv.3挥金如土勋章水中王者勋章Lv3Omega红宝石发售确认纪念章Alpha蓝宝石发售确认纪念章金银好CP-Ho-oh/LUGIA【里】金银好CP-Ho-oh/LUGIA【真·正常向】异化型LUGIA【M超梦版】

发表于 2016-3-21 22:48:22 | 显示全部楼层 |阅读模式
本帖最后由 jiangzhengwenjz 于 2016-3-21 23:04 编辑

源码请在github下载zip压缩包:https://github.com/jiangzhengwenjz/cmda6

请注意需自行安装devikitarm并把它的bin路径加到PATH变量,而且要装make

好久没改版了,这次拿C语言小试牛刀,不得不说用C语言改版还是很方便的,唯一搞不懂的是怎么确定函数写入的相对位置,所以这个问题暂时没解决只能手动来:|

使用方法则因为没有时间,所以暂时直接拿发到外网的版本凑下数,看最近有没有空翻成中文:
Introduction:
cmdA6 means the command in script whose index is 0xA6. As we all know, it is used in the level script in the map 1.111 in FR (in ICEFALL CAVE)
Let's see the original scripts:
(Type 5)
  1. #org 0x163D54
  2. cmda6 0x4 //the command we're hacking
  3. end
复制代码
(Type 1)
  1. special 0x135 //I've rewritten this one
  2. end
复制代码
(Type 2)
  1. //---------------
  2. #org 0x163D65
  3. lockall
  4. pause 0x14
  5. applymovement 0xFF 0x8163D7F
  6. waitmovement 0x0
  7. sound 0x25
  8. pause 0x3C
  9. warphole 0x1 0x70
  10. waitstate
  11. releaseall
  12. end
  13. //-----------
  14. // Movements
  15. //-----------
  16. #org 0x163D7F
  17. #raw 0x60 //Hide
  18. #raw 0xFE //End of Movements
复制代码
Note that the script has a var of 0x4001 and the var value is 0x0001.

The tile blocks used and their information:
Block Description        Block index        Block behavior byte
ICE                                0x359                0x26
BROKEN ICE                  0x35A                0x27
ICE HOLE                       0x35B                0x66(But we don't care)

How does it work:
(I suppose that you know nothing about ASM)
You can think that the type 5 script is always running (cmda6), and when you walk on the ICE block, it changes it to BROKEN ICE block. When you walk on the BROKEN ICE block, it changes it to ICE HOLE block, and do the same thing as "setvar 0x4001 1" to trigger the type 2 script. (warphole, etc.) I think the type 3 script is bugged so I've rewritten it to make the BROKEN ICE remain what they look like after entering the map.

How to use:
1. Download the zip archive and decompress it.
2. In that directory, you create a new folder called "build". (No quotation marks)
3. Modify the customization.h to meet your requirement. (See the next section) Don't forget to modify the offset to insert in the linker.lsc and linker2.lsc. For example, I make one of them 0x800000 and another 0x900000.
4. Press shift + right click and open the command line prompt (or your mintty), and type in make and press enter.
5. Now you can see that main.bin and sp135.bin are generated.
6. Prepare your BPRE ROM, and place FF at 0x6E8FC.
7. Insert them at the offsets you've defined in the 2 .lsc files. (linker.lsc for main.bin, linker2.lsc for sp135.bin)
8. Search 70 B5 81 B0 around the insert offset of main.bin. (For example, I inserted in at 0x800000 and I've found the hex value "70 B5 81 B0" at 0x8000BC. Repoint the table at 0x3A7310 and add a pointer at the end of it (+1) to the function you've found. (In this case, BD 00 80 08)
9. Goto the map you want and add 3 scripts:
Type5:
  1. cmda6 8 //if you add more to the table we've repointed, it should be 9, 10, 11...
  2. end
复制代码
Type1:
  1. callasm sp135.bin+1 //in this case, 0x8900001
  2. end
复制代码
Type2:
Please define it yourself because I don't know what you want to do. Be sure to use the variable you've defined in the "customization.h" and the value 1.
10. Done! Try to test it! (Don't forget to set the behavior bytes of your selected tileblocks in Advance Map)


How to define your own settings:
Open your decompressed archive and find the file "customization.h" in the \src\header folder. Use your text editor to open it. (like notepad, notepad++, vim, or any other things)
Then you just modify them as the comments said.
  1. #ifndef _CUSTOMIZATION_H
  2. #define _CUSTOMIZATION_H

  3. /*behavior bytes*/
  4. #define behavior_byte1 0x26
  5. #define behavior_byte2 0x27

  6. /*flags*/
  7. #define flag_start 0x1000 /* a series of flags to be used and they should be stable ones. The number of the flags are judged by the size of array.*/

  8. /*sound*/
  9. #define Snd_1 0x24 /*the sound index of "ice breaks"*/
  10. #define Snd_2 0x23 /*the sound index of "broken ice is transformed to a hole"*/

  11. /*tile block number*/
  12. #define tblock_1 0x359
  13. #define tblock_2 0x35A
  14. #define tblock_3 0x35B

  15. /*variable*/
  16. #define var_sc 0x4001

  17. /*coordinates*/
  18. /*These are the coordinates of your "ice blocks", don't forget to update the "9" after changing it. */
  19. const u8 coord_array[9][2] =
  20. {
  21.         {8,3},
  22.         {0xA,5},
  23.         {0xF,5},
  24.         {8,9},
  25.         {9,9},
  26.         {0x10,9},
  27.         {8,0xA},
  28.         {9,0xA},
  29.         {8,0xE},
  30. };

  31. #endif
复制代码
Credits:
Nintendo: for the game and its header file.
Knizz: for his idb.
Sturmvogel & Wodka: I took a look at the makefile they used to write my version.


Last section: what if you don't want the "block remaining function"?
1. Don't insert and use the sp135.bin.
2. Goto main.c and add "//" (comment mark) at the beginning of line 76 and 91 to deactivate the function calling.
回复

使用道具 举报

2万

回帖

13万

现金

347

勋章券

管理员

起源の钻角犀兽

Rank: 27Rank: 27Rank: 27

积分
51532

Missingno论坛十周年纪念物挥金如土勋章Lv3水中王者勋章Lv3时光印记Lv.3Omega红宝石发售确认纪念章Alpha蓝宝石发售确认纪念章

发表于 2016-3-21 23:17:58 | 显示全部楼层
2年没碰GBA改版了,不想仍有这么多进展,都可以直接用C了啊……
啊咧咧,又挖坑不填哎╮(╯▽╰)╭

告别真新镇后不知经过多久,擦伤,砍伤,朋友的数目,让我有点自豪,那时候因为流行而跑去买的,这双轻便的运动鞋,现在成了,找遍全世界也找不到的,最棒的破鞋子……
口袋中心·绿宝石·改(更新1.6.4版)
【口袋中心出品】魂银·壹式改点壹(全493)    【科普向】魂银中少有人注意到的洛奇亚传说故事
宝可梦卡牌 / 限定精灵图示    好吧,这是官方微博-_-    好吧,这是我的微博-_-
我的B站号    美术作品之我的宝可梦人设画    个人制作的FC魂斗罗2代hack版
回复 支持 反对

使用道具 举报

3344

回帖

3

现金

484

勋章券

超级版主

Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26

积分
21852
QQ

时光印记Lv.3挥金如土勋章水中王者勋章Lv3Omega红宝石发售确认纪念章Alpha蓝宝石发售确认纪念章金银好CP-Ho-oh/LUGIA【里】金银好CP-Ho-oh/LUGIA【真·正常向】异化型LUGIA【M超梦版】

 楼主| 发表于 2016-3-21 23:23:59 | 显示全部楼层
海のLUGIA 发表于 2016-3-21 23:17
2年没碰GBA改版了,不想仍有这么多进展,都可以直接用C了啊……

其实这编译器貌似很早就有,但不知为何一直没人用
而且C语言也有很坑爹的地方(当然可能是我C语言功底差233)
比如我要拿SP的值当参数,我就只会在里面强行用汇编指令
回复 支持 反对

使用道具 举报

2万

回帖

13万

现金

347

勋章券

管理员

起源の钻角犀兽

Rank: 27Rank: 27Rank: 27

积分
51532

Missingno论坛十周年纪念物挥金如土勋章Lv3水中王者勋章Lv3时光印记Lv.3Omega红宝石发售确认纪念章Alpha蓝宝石发售确认纪念章

发表于 2016-3-21 23:57:46 | 显示全部楼层
jiangzhengwenjz 发表于 2016-3-21 23:23
其实这编译器貌似很早就有,但不知为何一直没人用
而且C语言也有很坑爹的地方(当然可能是我C语言功底差 ...

那大概还是实用性问题了;这种反向贴近底层的操作,应该还是有蛮多地方汇编不可被替代?
啊咧咧,又挖坑不填哎╮(╯▽╰)╭

告别真新镇后不知经过多久,擦伤,砍伤,朋友的数目,让我有点自豪,那时候因为流行而跑去买的,这双轻便的运动鞋,现在成了,找遍全世界也找不到的,最棒的破鞋子……
口袋中心·绿宝石·改(更新1.6.4版)
【口袋中心出品】魂银·壹式改点壹(全493)    【科普向】魂银中少有人注意到的洛奇亚传说故事
宝可梦卡牌 / 限定精灵图示    好吧,这是官方微博-_-    好吧,这是我的微博-_-
我的B站号    美术作品之我的宝可梦人设画    个人制作的FC魂斗罗2代hack版
回复 支持 反对

使用道具 举报

3344

回帖

3

现金

484

勋章券

超级版主

Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26Rank: 26

积分
21852
QQ

时光印记Lv.3挥金如土勋章水中王者勋章Lv3Omega红宝石发售确认纪念章Alpha蓝宝石发售确认纪念章金银好CP-Ho-oh/LUGIA【里】金银好CP-Ho-oh/LUGIA【真·正常向】异化型LUGIA【M超梦版】

 楼主| 发表于 2016-3-22 12:07:26 | 显示全部楼层
海のLUGIA 发表于 2016-3-21 23:57
那大概还是实用性问题了;这种反向贴近底层的操作,应该还是有蛮多地方汇编不可被替代?

我想,他原来的代码应该是用C编的 那或许有办法弄,只是我还没想到方法罢了

点评

╮(╯▽╰)╭GBA就是纯C开发,这么一想很有道理  发表于 2016-3-22 12:27
回复 支持 反对

使用道具 举报

177

回帖

26

现金

3

勋章券

与恶势力的交锋

Rank: 7Rank: 7Rank: 7

积分
485

论坛十周年纪念物时光印记Lv.1水中王者勋章Lv1个别的十一人勋章


蟾蜍王 Lv:44
发表于 2016-3-22 17:40:53 | 显示全部楼层
虽然看不懂,不过感觉好高级
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 加入口袋中心

本版积分规则

手机版|Archiver|Pokemon Center

GMT+8, 2024-4-19 23:22 , Processed in 0.118781 second(s), 52 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表