@@ -35,57 +35,66 @@ func main() {
3535 log .Panic (err )
3636 }
3737
38- basePath := "Config/Cheats"
39- items , err := fs .ReadDir (basePath )
40- if err != nil {
41- log .Panic (err )
42- }
43-
4438 cheatDB := map [string ]map [string ]Cheat {}
45- currentGame := ""
46- currentCheat := ""
47- for _ , item := range items {
48- file , err := fs .Open ( filepath . Join ( basePath , item . Name ()) )
39+
40+ paths := [] string { "Config/Cheats" , "Config/Enhancements" }
41+ for _ , basePath := range paths {
42+ items , err := fs .ReadDir ( basePath )
4943 if err != nil {
5044 log .Panic (err )
5145 }
52- defer file .Close () //nolint:errcheck
53- scanner := bufio .NewScanner (file )
54- for scanner .Scan () {
55- game := cheatDB [currentGame ]
56- cheat := game [currentCheat ]
57- if strings .HasPrefix (scanner .Text (), "[" ) {
58- currentGame = strings .Trim (scanner .Text (), "[]" )
59- cheatDB [currentGame ] = map [string ]Cheat {}
60- } else if strings .HasPrefix (scanner .Text (), "Name=" ) {
61- // do nothing
62- } else if strings .HasPrefix (scanner .Text (), "$" ) {
63- currentCheat = strings .TrimPrefix (scanner .Text (), "$" )
64- game [currentCheat ] = Cheat {}
65- cheatDB [currentGame ] = game
66- } else if strings .HasPrefix (scanner .Text (), "Note=" ) {
67- cheat .Note = strings .TrimPrefix (scanner .Text (), "Note=" )
68- game [currentCheat ] = cheat
69- } else if scanner .Text () == "" {
70- // do nothing
71- } else if strings .Contains (scanner .Text (), "?" ) && cheat .Options == nil {
72- cheat .Options = map [string ]string {}
73- cheat .Data = append (cheat .Data , scanner .Text ())
74- game [currentCheat ] = cheat
75- } else if cheat .Options != nil && len (strings .Split (scanner .Text (), " " )[0 ]) < 8 {
76- cheat .Options [strings .Join (strings .Split (scanner .Text (), " " )[1 :], " " )] = strings .Split (scanner .Text (), " " )[0 ]
77- game [currentCheat ] = cheat
78- } else if isHex (scanner .Text ()) {
79- cheat .Data = append (cheat .Data , scanner .Text ())
80- game [currentCheat ] = cheat
81- } else {
82- delete (game , currentCheat )
83- log .Printf ("Unknown line in cheat file %s, %s: %s\n " , filepath .Join (basePath , item .Name ()), currentCheat , scanner .Text ())
46+ for _ , item := range items {
47+ currentGame := ""
48+ currentCheat := ""
49+ file , err := fs .Open (filepath .Join (basePath , item .Name ()))
50+ if err != nil {
51+ log .Panic (err )
52+ }
53+ defer file .Close () //nolint:errcheck
54+ scanner := bufio .NewScanner (file )
55+ for scanner .Scan () {
56+ if strings .HasPrefix (scanner .Text (), "[" ) {
57+ currentGame = strings .Trim (scanner .Text (), "[]" )
58+ if cheatDB [currentGame ] == nil {
59+ cheatDB [currentGame ] = map [string ]Cheat {}
60+ }
61+ } else if strings .HasPrefix (scanner .Text (), "Name=" ) {
62+ // do nothing
63+ } else if strings .HasPrefix (scanner .Text (), "$" ) {
64+ currentCheat = strings .TrimPrefix (scanner .Text (), "$" )
65+ cheatDB [currentGame ][currentCheat ] = Cheat {}
66+ } else if strings .HasPrefix (scanner .Text (), "Note=" ) && currentCheat != "" {
67+ current := cheatDB [currentGame ][currentCheat ]
68+ current .Note = strings .TrimPrefix (scanner .Text (), "Note=" )
69+ cheatDB [currentGame ][currentCheat ] = current
70+ } else if scanner .Text () == "" {
71+ // do nothing
72+ } else if strings .Contains (scanner .Text (), "?" ) && currentCheat != "" && cheatDB [currentGame ][currentCheat ].Options == nil {
73+ current := cheatDB [currentGame ][currentCheat ]
74+ current .Options = map [string ]string {}
75+ current .Data = append (cheatDB [currentGame ][currentCheat ].Data , scanner .Text ())
76+ cheatDB [currentGame ][currentCheat ] = current
77+ } else if currentCheat != "" && cheatDB [currentGame ][currentCheat ].Options != nil && len (strings .Split (scanner .Text (), " " )[0 ]) < 8 {
78+ cheatDB [currentGame ][currentCheat ].Options [strings .Join (strings .Split (scanner .Text (), " " )[1 :], " " )] = strings .Split (scanner .Text (), " " )[0 ]
79+ } else if isHex (scanner .Text ()) && currentCheat != "" {
80+ current := cheatDB [currentGame ][currentCheat ]
81+ current .Data = append (cheatDB [currentGame ][currentCheat ].Data , scanner .Text ())
82+ cheatDB [currentGame ][currentCheat ] = current
83+ } else if currentCheat != "" && (strings .HasPrefix (scanner .Text (), "OnByDefault=1" ) || strings .HasPrefix (scanner .Text (), "PluginList=" )) {
84+ // PJ64 specific, ignore
85+ delete (cheatDB [currentGame ], currentCheat )
86+ log .Printf ("Ignoring line in cheat file %s, %s: %s\n " , filepath .Join (basePath , item .Name ()), currentCheat , scanner .Text ())
87+ currentCheat = ""
88+ } else if currentCheat != "" {
89+ delete (cheatDB [currentGame ], currentCheat )
90+ log .Printf ("Unknown line in cheat file %s, %s: %s\n " , filepath .Join (basePath , item .Name ()), currentCheat , scanner .Text ())
91+ currentCheat = ""
92+ }
8493 }
85- }
8694
87- if err := scanner .Err (); err != nil {
88- log .Panic (err )
95+ if err := scanner .Err (); err != nil {
96+ log .Panic (err )
97+ }
8998 }
9099 }
91100
0 commit comments