diff --git a/hiddata.c b/hiddata.c index 6a9f5dd..c17f202 100644 --- a/hiddata.c +++ b/hiddata.c @@ -96,6 +96,8 @@ static void hiddata_processCommandBuffer(struct hiddata_ops *ops) // TODO : Range checking // cmdbuf[] : RQ, CHN, LEN, data[] channel = cmdbuf[1]; + if (channel >= NUM_CHANNELS) + break; cmdbuf_len = gcn64_transaction(channel, cmdbuf+3, cmdbuf[2], cmdbuf + 3, CMDBUF_SIZE-3); cmdbuf[2] = cmdbuf_len; cmdbuf_len += 3; // Answer: RQ, CHN, LEN, data[] @@ -131,7 +133,10 @@ static void hiddata_processCommandBuffer(struct hiddata_ops *ops) case RQ_GCN64_GET_CONTROLLER_TYPE: // CMD : RQ, CHN // Answer: RQ, CHN, TYPE - cmdbuf[2] = current_pad_type; + channel = cmdbuf[1]; + if (channel >= NUM_CHANNELS) + break; + cmdbuf[2] = current_pad_type[channel]; cmdbuf_len = 3; break; case RQ_GCN64_SET_VIBRATION: diff --git a/main.c b/main.c index ff9c472..4492bc1 100644 --- a/main.c +++ b/main.c @@ -364,13 +364,13 @@ void hwinit(void) } -unsigned char current_pad_type = CONTROLLER_IS_ABSENT; +unsigned char current_pad_type[NUM_CHANNELS] = { }; Gamepad *detectPad(unsigned char chn) { - current_pad_type = gcn64_detectController(chn); + current_pad_type[chn] = gcn64_detectController(chn); - switch (current_pad_type) + switch (current_pad_type[chn]) { case CONTROLLER_IS_ABSENT: case CONTROLLER_IS_UNKNOWN: diff --git a/main.h b/main.h index 70e86f7..dcb20a6 100644 --- a/main.h +++ b/main.h @@ -1,6 +1,8 @@ #ifndef _main_h__ #define _main_h__ -extern unsigned char current_pad_type; +#include "config.h" + +extern unsigned char current_pad_type[NUM_CHANNELS]; #endif // _main_h__