Skip to content

Commit c944b73

Browse files
committed
add default rewriting rules
1 parent 40482fa commit c944b73

3 files changed

Lines changed: 21 additions & 17 deletions

File tree

Boxes/boxes.ml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11

22
exception BoxFittingError of string
33

4+
type rewrite_rules = (int list * int list) list
5+
let parse_code s =
6+
let n = String.length s in
7+
if n mod 8 <> 0 then failwith "Invalid byte sequence length" ;
8+
List.init (n / 2) (fun i -> int_of_string ("0x" ^ String.sub s (i * 2) 2))
9+
let parse_rewrite_rule s =
10+
match String.split_on_char ':' s with
11+
| [pre; post] -> (parse_code pre, parse_code post)
12+
| _ -> failwith "Invalid rule format"
13+
let parse_rewrite_rules str =
14+
List.map parse_rewrite_rule (String.split_on_char ';' str)
15+
416
type fillers =
5-
{ nop_code:int list ; nop_code_alt:int list; fillers:int list array; rewriting:(int list * int list) list }
17+
{ nop_code:int list ; nop_code_alt:int list; fillers:int list array; rewriting:rewrite_rules }
618
let default_fillers () = {
719
nop_code =
820
if !Settings.game = Ruby || !Settings.game = Sapphire then
@@ -41,7 +53,10 @@ let default_fillers () = {
4153
[0x00 ; 0x00 ; 0x00 ; 0xFF](* FF000000 *) ;
4254
|]
4355
;
44-
rewriting = []
56+
rewriting = [
57+
parse_rewrite_rule "FFBBBBBB00000000FFFFBBBB:FFBBFFFFFFFFFFFFFFFFBBBB" ;
58+
parse_rewrite_rule "FFFFBBBB00000000FFFFFFBB:FFFFBBFFFFFFFFFFFFFFFFBB"
59+
]
4560
}
4661

4762
let padding = [0x00 ; 0x00 ; 0x00 ; 0x00]

Boxes/boxes.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11

22
exception BoxFittingError of string
33

4+
type rewrite_rules = (int list * int list) list
5+
val parse_rewrite_rules : string -> rewrite_rules
46
type fillers =
5-
{ nop_code:int list ; nop_code_alt:int list; fillers:int list array; rewriting:(int list * int list) list }
7+
{ nop_code:int list ; nop_code_alt:int list; fillers:int list array; rewriting:rewrite_rules }
68
val default_fillers : unit -> fillers
79

810
val fit_codes_into_boxes :

Main/ace_common.ml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ let compare_and_print_commands fmt data descr exit =
3333
in
3434
aux data descr false 0
3535

36-
let parse_rewrite str =
37-
let parse_code s =
38-
let n = String.length s in
39-
if n mod 8 <> 0 then failwith "Invalid byte sequence length" ;
40-
List.init (n / 2) (fun i -> int_of_string ("0x" ^ String.sub s (i * 2) 2))
41-
in
42-
let parse_rule s =
43-
match String.split_on_char ':' s with
44-
| [pre; post] -> (parse_code pre, parse_code post)
45-
| _ -> failwith "Invalid rule format"
46-
in
47-
List.map parse_rule (String.split_on_char ';' str)
48-
4936
let main fmt env (headers,headers2) parsed exit =
5037
let onlyraw =
5138
match Preprocess.get_param headers "onlyraw" with
@@ -89,7 +76,7 @@ let main fmt env (headers,headers2) parsed exit =
8976
let rewriting =
9077
match Preprocess.get_param headers "rewrite" with
9178
| HNone -> default_fillers.rewriting
92-
| HString str -> parse_rewrite str
79+
| HString str -> Boxes.parse_rewrite_rules str
9380
| _ -> failwith "Invalid headers."
9481
in
9582
let fill_last =

0 commit comments

Comments
 (0)