Skip to content

Commit ae33076

Browse files
committed
Added Wii cheats selection menu
1 parent 3489dd5 commit ae33076

File tree

13 files changed

+375
-44
lines changed

13 files changed

+375
-44
lines changed

driveRoot/rvloader/themes/main/scripts/gamesview.lua

+65-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ require 'scripts/gc+map'
66
require 'scripts/topbarcmd'
77

88
menuSystem = MenuSystem()
9+
cheatsMenuSystem = MenuSystem()
910

1011
function init()
1112
showingGameConfig = false
13+
showingGameCheats = false
1214
showingGC2Wiimote = false
1315
showingGCPMapping = false
1416

@@ -97,20 +99,29 @@ function init()
9799
menuSystem:addEntry("Configure GC2Wiimote", false)
98100
menuSystem:setEntrySelectAction(activateGC2WMapping)
99101
menuSystem:addYesNoEntry("Patch MX chip", false, GamesView.config.YES, GamesView.config.NO)
102+
menuSystem:addYesNoEntry("Enable Cheats", false, GamesView.config.YES, GamesView.config.NO)
103+
menuSystem:addEntry("Configure cheats", false)
104+
menuSystem:setEntrySelectAction(activateCheatsConfig)
100105
elseif GamesView.getGamesType() == GamesView.gameType.WII_CHANNEL then
101106
menuSystem:addYesNoEntry("Enable WiFi", false, GamesView.config.YES, GamesView.config.NO)
102107
menuSystem:addYesNoEntry("Enable Bluetooth", false, GamesView.config.YES, GamesView.config.NO)
103108
menuSystem:addYesNoEntry("Enable GC2Wiimote", false, GamesView.config.YES, GamesView.config.NO)
104109
menuSystem:addEntry("Configure GC2Wiimote", false)
105110
menuSystem:setEntrySelectAction(activateGC2WMapping)
106111
menuSystem:addYesNoEntry("Patch MX chip", false, GamesView.config.YES, GamesView.config.NO)
112+
menuSystem:addYesNoEntry("Enable Cheats", false, GamesView.config.YES, GamesView.config.NO)
113+
menuSystem:addEntry("Configure cheats", false)
114+
menuSystem:setEntrySelectAction(activateCheatsConfig)
107115
elseif GamesView.getGamesType() == GamesView.gameType.WII_VC then
108116
menuSystem:addYesNoEntry("Enable WiFi", false, GamesView.config.YES, GamesView.config.NO)
109117
menuSystem:addYesNoEntry("Enable Bluetooth", false, GamesView.config.YES, GamesView.config.NO)
110118
menuSystem:addYesNoEntry("Enable GC2Wiimote", false, GamesView.config.YES, GamesView.config.NO)
111119
menuSystem:addEntry("Configure GC2Wiimote", false)
112120
menuSystem:setEntrySelectAction(activateGC2WMapping)
113121
menuSystem:addYesNoEntry("Patch MX chip", false, GamesView.config.YES, GamesView.config.NO)
122+
menuSystem:addYesNoEntry("Enable Cheats", false, GamesView.config.YES, GamesView.config.NO)
123+
menuSystem:addEntry("Configure cheats", false)
124+
menuSystem:setEntrySelectAction(activateCheatsConfig)
114125
end
115126

116127
fonts = {}
@@ -122,6 +133,12 @@ function init()
122133
menuSystem.columnWidth = SETTINGS_WIN_WIDTH
123134
menuSystem.sideMargin = SETTINGS_SIDE_MARGIN
124135

136+
cheatsMenuSystem.font = fonts[SETTING_FONT_SIZE]
137+
cheatsMenuSystem.lineHeight = SETTING_EL_HEIGHT
138+
cheatsMenuSystem.columnWidth = SETTINGS_WIN_WIDTH
139+
cheatsMenuSystem.sideMargin = SETTINGS_SIDE_MARGIN
140+
cheatsMenuSystem.lineWidth = 280
141+
125142
initGC2WiimoteConf()
126143
initGCPMapConf()
127144
end
@@ -137,6 +154,17 @@ function activateGC2WMapping(index)
137154
showingGC2Wiimote = true
138155
end
139156

157+
function activateCheatsConfig(index)
158+
gameCheats = GamesView.readGameCheats(selectedGame)
159+
cheatsMenuSystem:clearEntries()
160+
cheatsMenuSystem:reset()
161+
for i = 1, #gameCheats do
162+
cheatsMenuSystem:addYesNoEntry(gameCheats[i], false, GamesView.config.YES, GamesView.config.NO)
163+
cheatsMenuSystem:setEntryValue(gameCheats[i], GamesView.getGameConfigValue("Cheat_" .. GamesView.getCheatNameHash(gameCheats[i])))
164+
end
165+
showingGameCheats = true
166+
end
167+
140168
function draw(onFocus)
141169
if showingGC2Wiimote then
142170
topBarSetText("GC2Wiimote: " .. GamesView.getGameName(selectedGame))
@@ -216,7 +244,9 @@ function draw(onFocus)
216244
Gfx.popScissorBox()
217245
Gfx.popMatrix()
218246

219-
if showingGameConfig then
247+
if showingGameCheats then
248+
drawGameCheats(onFocus)
249+
elseif showingGameConfig then
220250
drawGameConfig(onFocus)
221251
end
222252
end
@@ -236,7 +266,10 @@ function handleInputs(onFocus)
236266
return
237267
end
238268

239-
if showingGameConfig then
269+
if showingGameCheats then
270+
handleGameCheats()
271+
return
272+
elseif showingGameConfig then
240273
handleGameConfig()
241274
return
242275
end
@@ -320,7 +353,6 @@ function handleInputs(onFocus)
320353
--Show game config if requested
321354
if down.BUTTON_B then
322355
GamesView.openGameConfig(selectedGame)
323-
GamesView.getGameConfigValue("Enable Bluetooth")
324356
configOptions = menuSystem:getEntriesWithOptions()
325357
for i = 1, #configOptions do
326358
menuSystem:setEntryValue(configOptions[i], GamesView.getGameConfigValue(configOptions[i]))
@@ -370,3 +402,33 @@ function handleGameConfig()
370402

371403
menuSystem:handleInputs()
372404
end
405+
406+
function drawGameCheats(onFocus)
407+
Gfx.pushMatrix()
408+
Gfx.identity()
409+
Gfx.pushIdentityScissorBox()
410+
Gfx.drawRectangle(0, 0, Gui.getScreenSize().x, Gui.getScreenSize().y, Gfx.RGBA8(0x00, 0x00, 0x00, 0xA0))
411+
Gfx.translate((Gui.getScreenSize().x - SETTINGS_WIN_WIDTH) / 2, (Gui.getScreenSize().y - SETTINGS_WIN_HEIGHT) / 2)
412+
Gfx.pushScissorBox(SETTINGS_WIN_WIDTH, SETTINGS_WIN_HEIGHT)
413+
Gfx.drawRectangle(0, 0, SETTINGS_WIN_WIDTH, SETTINGS_WIN_HEIGHT, Gfx.RGBA8(0x2D, 0x2D, 0x2D, 0xB0))
414+
415+
cheatsMenuSystem:printMenu(onFocus)
416+
417+
Gfx.popScissorBox()
418+
Gfx.popScissorBox()
419+
Gfx.popMatrix()
420+
end
421+
422+
function handleGameCheats()
423+
local down = Pad.gendown(0)
424+
425+
if down.BUTTON_B then
426+
for i = 1, #gameCheats do
427+
GamesView.setGameConfigValue("Cheat_" .. GamesView.getCheatNameHash(gameCheats[i]), cheatsMenuSystem:getEntryValue(gameCheats[i]))
428+
end
429+
showingGameCheats = false
430+
return
431+
end
432+
433+
cheatsMenuSystem:handleInputs()
434+
end

driveRoot/rvloader/themes/main/scripts/menuSystem.lua

+34-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ MenuSystem = class()
66
function MenuSystem:init()
77
self.font = 0
88
self.lineHeight = 32
9+
self.lineWidth = 1000
10+
self.lineScroll = 0
11+
self.lineScrollTextGap = 32
12+
self.lineScrollTextTimeRef = 0
13+
self.lineScrollTextTime = 50
914
self.columnWidth = 100
1015
self.sideMargin = 16
1116
self.lineI = 1
@@ -77,6 +82,7 @@ end
7782

7883
function MenuSystem:printLine(str, sel)
7984
local oldAlignment = Gfx.getFontVerticalAlignment(self.font)
85+
local strWidth = Gfx.getTextWidth(self.font, str)
8086
Gfx.setFontVerticalAlignment(self.font, Gfx.CENTER_ALIGN)
8187
local oldColor = Gfx.getFontColor(self.font)
8288
if self.lineI == sel then
@@ -85,7 +91,25 @@ function MenuSystem:printLine(str, sel)
8591
else
8692
Gfx.setFontColor(self.font, Gfx.RGBA8(0xA0, 0xA0, 0xA0, 0xFF))
8793
end
88-
Gfx.print(self.font, 2 * self.sideMargin, self.lineY - 0.5 * self.lineHeight, str)
94+
Gfx.pushMatrix()
95+
Gfx.translate(2 * self.sideMargin, self.lineY - self.lineHeight)
96+
Gfx.pushScissorBox(self.lineWidth, self.lineHeight)
97+
if self.lineI == sel then
98+
Gfx.translate(-self.lineScroll, 0)
99+
Gfx.print(self.font, 0, 0.5 * self.lineHeight, str)
100+
if strWidth > self.lineWidth then
101+
Gfx.print(self.font, strWidth + self.lineScrollTextGap, 0.5 * self.lineHeight, str)
102+
self.lineScroll = (Time.getms() - self.lineScrollTextTimeRef) // self.lineScrollTextTime
103+
if self.lineScroll > strWidth + self.lineScrollTextGap then
104+
self.lineScroll = self.lineScroll - (strWidth + self.lineScrollTextGap)
105+
self.lineScrollTextTimeRef = Time.getms() - self.lineScroll * self.lineScrollTextTime
106+
end
107+
end
108+
else
109+
Gfx.print(self.font, 0, 0.5 * self.lineHeight, str)
110+
end
111+
Gfx.popScissorBox()
112+
Gfx.popMatrix()
89113
Gfx.drawLine(0, self.lineY, self.columnWidth, self.lineY, 1, self.lineColor)
90114
Gfx.setFontColor(self.font, oldColor)
91115
self.lineI = self.lineI + 1
@@ -137,6 +161,11 @@ function MenuSystem:addSpacer(str)
137161
Gfx.setFontVerticalAlignment(self.font, oldAlignment)
138162
end
139163

164+
function MenuSystem:clearEntries()
165+
self.entries = {}
166+
self.entriesIndex = {}
167+
end
168+
140169
function MenuSystem:increaseEntryValue(index)
141170
if index >= 1 and index <= #self.entries then
142171
if #self.entries[index].optionsValue > 0 then
@@ -240,8 +269,12 @@ function MenuSystem:handleInputs()
240269

241270
if down.BUTTON_DOWN and self.selLine < #self.entries then
242271
self.selLine = self.selLine + 1
272+
self.lineScroll = 0
273+
self.lineScrollTextTimeRef = Time.getms()
243274
elseif down.BUTTON_UP and self.selLine > 1 then
244275
self.selLine = self.selLine - 1
276+
self.lineScroll = 0
277+
self.lineScrollTextTimeRef = Time.getms()
245278
end
246279

247280
self.selLineY = self.selLine * self.lineHeight

main/include/gui/guigamesview.h

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "gc2wiimote.h"
1010
#include "guiluaelement.h"
1111
#include "gcplus.h"
12+
#include "cheats.h"
1213

1314
typedef enum {
1415
GC_GAME = 0,
@@ -27,6 +28,8 @@ class GuiGamesView : public GuiLuaElement {
2728

2829
Config gameConfig;
2930

31+
Cheat cheatCodes;
32+
3033
//GC2Wiimote
3134
WMEmuConfig_t emuConfig;
3235
std::string lastGC2WiimoteConfigPath;
@@ -223,6 +226,8 @@ class GuiGamesView : public GuiLuaElement {
223226
static int lua_saveGameConfig(lua_State* L);
224227
static int lua_setGameConfigValue(lua_State* L);
225228
static int lua_getGameConfigValue(lua_State* L);
229+
static int lua_readGameCheats(lua_State* L);
230+
static int lua_getCheatNameHash(lua_State* L);
226231
static int lua_openGC2WiimoteGameConfig(lua_State* L);
227232
static int lua_saveGC2WiimoteGameConfig(lua_State* L);
228233
static int lua_setGC2WiimoteGameConfigValue(lua_State* L);

main/include/titles/cheats.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <stdint.h>
5+
#include <utility>
6+
#include <map>
7+
#include <list>
8+
#include <vector>
9+
#include <algorithm>
10+
11+
class Cheat {
12+
public:
13+
typedef struct {
14+
std::list<std::pair<uint32_t, uint32_t>> codesList;
15+
std::string notes;
16+
bool active;
17+
} CheatCode;
18+
19+
private:
20+
std::map<std::string, CheatCode> cheatCodes;
21+
22+
public:
23+
std::map<std::string, CheatCode>::iterator begin() {return cheatCodes.begin();}
24+
std::map<std::string, CheatCode>::iterator end() {return cheatCodes.end();}
25+
void parseFile(const std::string filename);
26+
static std::string getCheatNameHash(std::string cheatName);
27+
void setCheatActive(const std::string cheatName, bool active);
28+
bool getCheatActive(const std::string cheatName);
29+
std::vector<uint32_t> generateGCT();
30+
31+
};

main/include/titles/titles.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ class GameContainer {
1919
std::string path;
2020
std::string coverPath;
2121
std::string confPath;
22+
std::string cheatPath;
2223
std::string gameIDString;
2324
u32 gameID;
2425
GuiImage* image;
2526

26-
GameContainer(std::string _name, std::string _path, std::string _coverPath, std::string _confPath, std::string _gameIDString, u32 _gameID) : name(_name), path(_path), coverPath(_coverPath), confPath(_confPath), gameIDString(_gameIDString), gameID(_gameID), image(NULL) {}
27+
GameContainer(std::string _name, std::string _path, std::string _coverPath, std::string _confPath, std::string _cheatPath, std::string _gameIDString, u32 _gameID) : name(_name), path(_path), coverPath(_coverPath), confPath(_confPath), cheatPath(_cheatPath), gameIDString(_gameIDString), gameID(_gameID), image(NULL) {}
2728

2829
static bool compare(GameContainer gc1, GameContainer gc2) {
2930
const char* buffer1 = gc1.name.c_str();

main/include/utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
bool matchStr(const char* str1, const char* str2);
66
int readFile(const char* path, uint8_t** buffer, uint32_t* fileSize);
77
int writeFile(const char* path, void* buffer, uint32_t fileSize);
8+
bool fileExists(const char* path);
9+
bool fileExists(const std::string path);

0 commit comments

Comments
 (0)