From 1c09d834291e7b33c394111f3ad95e3d920752e9 Mon Sep 17 00:00:00 2001 From: Tyler Genter Date: Sun, 22 Feb 2009 16:15:54 -0800 Subject: [PATCH] did stuff --- src/Execute.h | 18 ++++++++ src/Game.cpp | 14 ++++++ src/Game.h | 28 ++++++++++++ src/Hotspot.cpp | 22 ++++++++++ src/Hotspot.h | 40 +++++++++++++++++ src/Main.cpp | 12 +++--- src/Makefile | 10 ++++- src/Name.cpp | 19 +++++++++ src/Name.h | 38 +++++++++++++++++ src/Plst.cpp | 35 +++++++++++++++ src/Plst.h | 24 +++++++++++ src/Script.cpp | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Script.h | 18 +++++--- src/Tbmp.cpp | 10 ++--- src/Variable.cpp | 12 ++++++ src/Variable.h | 54 +++++++++++++++++++++++ 16 files changed, 464 insertions(+), 18 deletions(-) create mode 100644 src/Execute.h create mode 100644 src/Game.cpp create mode 100644 src/Game.h create mode 100644 src/Hotspot.cpp create mode 100644 src/Hotspot.h create mode 100644 src/Name.cpp create mode 100644 src/Name.h create mode 100644 src/Plst.cpp create mode 100644 src/Plst.h create mode 100644 src/Variable.cpp create mode 100644 src/Variable.h diff --git a/src/Execute.h b/src/Execute.h new file mode 100644 index 0000000..b9b1ca0 --- /dev/null +++ b/src/Execute.h @@ -0,0 +1,18 @@ + +#ifndef _EXECUTE_H_ +#define _EXECUTE_H_ + +#include "Common.h" + +class Execute { + +protected: + friend class Handler; + + virtual void runCmd (uint16_t *cmd) = 0; + virtual uint16_t getVar (uint16_t var) = 0; + +}; + +#endif + diff --git a/src/Game.cpp b/src/Game.cpp new file mode 100644 index 0000000..6f23126 --- /dev/null +++ b/src/Game.cpp @@ -0,0 +1,14 @@ + +#include + +#include "Game.h" + +using namespace std; + + + + +Game::Game () + + + diff --git a/src/Game.h b/src/Game.h new file mode 100644 index 0000000..101ac1b --- /dev/null +++ b/src/Game.h @@ -0,0 +1,28 @@ + +#ifndef _GAME_H_ +#define _GAME_H_ + +#include "Stack.h" +#include "Variable.h" + +#include "Execute.h" +#include "Common.h" + +class Game: public Execute { + + Stack *currentStack; + Variable *variable; + +// Card *currentCard; + + void run (uint16_t *cmd); + uint16_t getVariable (int id); + + +public: + Game (); + +}; + +#endif + diff --git a/src/Hotspot.cpp b/src/Hotspot.cpp new file mode 100644 index 0000000..963039b --- /dev/null +++ b/src/Hotspot.cpp @@ -0,0 +1,22 @@ + + +#include "Hotspot.h" + + +HsptRecord::HsptRecord (File *file, int addr) { + + nameRec = file->readSShort (addr + 2); + left = file->readSShort (addr + 4); + top = file->readSShort (addr + 6); + right = file->readSShort (addr + 8); + bottom = file->readSShort (addr + 10); + + mouseCursor = file->readUShort (addr + 14); + index = file->readUShort (addr + 16); + + + +} + + + diff --git a/src/Hotspot.h b/src/Hotspot.h new file mode 100644 index 0000000..f7273a5 --- /dev/null +++ b/src/Hotspot.h @@ -0,0 +1,40 @@ + +#ifndef _HOTSPOT_H_ +#define _HOTSPOT_H_ + +#include "File.h" +#include "Script.h" + + +Class HsptRecord { + + int16_t nameRec, left, top, right, bottom; + uint16_t mouseCursor, index; + + Script *script; + + int length; + +public: + HsptRecord (File *file, int addr); + + int getLength () { + return length; + } + + int getIndex () { + return index; + } + + bool isInside (int16_t x, int16_t y) { + if ((x > left) && (x < right)) + if ((y > top) && (y < bottom)) + return true; + return false; + } + + +}; + +#endif + diff --git a/src/Main.cpp b/src/Main.cpp index 128b68d..ba96a54 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,14 +1,16 @@ #include "Stack.h" -#include "Tbmp.h" + +#include "Name.h" + +#include "Variable.h" int main () { Stack *stack; - stack = new Stack ("g_Data.MHK"); - Tbmp *img; - img = new Tbmp (stack, 7); - img->dump ("blah"); + stack = new Stack ("newGame.rvn"); + Name name (stack, 1); + name.dump (); } diff --git a/src/Makefile b/src/Makefile index 10e9512..903b6ec 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,19 +8,25 @@ CPP=g++ SRCS=Common.cpp\ File.cpp\ + Game.cpp\ Main.cpp\ Mohawk.cpp\ + Name.cpp\ Script.cpp\ Stack.cpp\ - Tbmp.cpp + Tbmp.cpp\ + Variable.cpp OBJS=Common.o\ File.o\ + Game.o\ Main.o\ Mohawk.o\ + Name.o\ Script.o\ Stack.o\ - Tbmp.o + Tbmp.o\ + Variable.o all: riven-wahrk diff --git a/src/Name.cpp b/src/Name.cpp new file mode 100644 index 0000000..c156998 --- /dev/null +++ b/src/Name.cpp @@ -0,0 +1,19 @@ + + +#include + +#include "Name.h" + +string Name::getString (int n) { + + string result = string ((const char*)file->readCharArray (2 + count*4 + file->readUShort (2 + n*2))); + + // for some reason, there is 0xbd at the beginning and end of some strings + string::size_type loc; + while ((loc = result.find ("\275")) != string::npos) + result = result.erase (loc, 1); + + return result; + +} + diff --git a/src/Name.h b/src/Name.h new file mode 100644 index 0000000..f33cc10 --- /dev/null +++ b/src/Name.h @@ -0,0 +1,38 @@ + +#ifndef _NAME_H_ +#define _NAME_H_ + +#include +#include + +#include "Common.h" +#include "File.h" + +using namespace std; + +class Name { + + File *file; + uint16_t count; + +public: + Name (Stack *stack, int id) { + file = new File (stack, Resource::NAME, id); + count = file->readUShort (0); + } + + ~Name () { + delete file; + } + + string getString (int n); + + void dump () { + for (int i=0; ireadUShort (0); + +} + +Plst::get (int index, uint16_t *bmpId, uint16_t *left, uint16_t *top, uint16_t *right, uint16_t *bottom) { + + for (int=0; ireadUShort (2 + 12*i)) { + + *bmpId = file->readUShort (2 + 12*i + 2); + *left = file->readUShort (2 + 12*i + 4); + *top = file->readUShort (2 + 12*i + 6); + *right = file->readUShort (2 + 12*i + 8); + *bottom = file->readUShort (2 + 12*i + 10); + break; + } + } + +} + +Plst::draw (int record, Framebuffer *buffer) { + + + +} + diff --git a/src/Plst.h b/src/Plst.h new file mode 100644 index 0000000..8fecd4f --- /dev/null +++ b/src/Plst.h @@ -0,0 +1,24 @@ + +#ifndef _PLST_H_ +#define _PLST_H_ + +#include "File.h" +#include "Tbmp.h" + +class Plst { + + Stack *stack; + File *file; + +public: + Plst (Stack *stackIn, int id); + + get (int index, uint16_t *bmpId, uint16_t *left, uint16_t *top, uint16_t *right, uint16_t *bottom); + + draw (int record, Framebuffer *buffer); + +} + + +#endif + diff --git a/src/Script.cpp b/src/Script.cpp index 44e2486..4f56839 100644 --- a/src/Script.cpp +++ b/src/Script.cpp @@ -43,6 +43,126 @@ int Handler::findSegmentSize (int offset) { +void Handler::runSegment (int addr) { + int i; + addr++; + for (i=cmdList[addr-1]; i>0; i--) { + if (cmdList[addr] == 8) { // if statement + + bool ran = false; + int ffff = 0; + uint16_t val = getVar (cmdList[addr + 2]); + addr += 4; + for (int j=cmdList[addr-1]; j>0; j--) { + if (cmdList[addr] == 0xffff) + ffff = addr; + addr++; + if (cmdList[addr-1] == val) { + ran = true; + cout << "{\n"; + runSegment (addr); + cout << "}\n"; + } + addr += cmdLength->find(addr)->second; + + // there is a default statement + if (!ran) + if (ffff != 0) + runSegment (ffff); + } + + } else { + + runCmd (cmdList + addr); + + addr += 2 + cmdList[addr+1]; + } + } +}; + + +Handler::runCmd (uint16_t *cmd) { + // first byte is command, second is number of args + switch (cmd[0]) { + case 1: + cout << "cmd draw tbmp\n"; + break; + case 2: + cout << "cmd go to card\n"; + break; + case 3: + cout << "cmd activate inline slst\n"; + break; + case 4: + cout << "cmd play local twav\n"; + break; + case 7: + cout << "cmd set variable value\n"; + break; + case 9: + cout << "cmd enable hotspot\n"; + break; + case 10: + cout << "cmd disable hotspot\n"; + break; + case 13: + cout << "cmd set mouse cursor\n"; + break; + case 14: + cout << "cmd pause script\n"; + break; + case 17: + cout << "cmd call external command\n"; + break; + case 18: + cout << "cmd transition\n"; + break; + case 19: + cout << "cmd reload card\n"; + break; + case 20: + cout << "cmd disable screen update\n"; + break; + case 21: + cout << "cmd enable screen update\n"; + break; + case 24: + cout << "cmd increment variable\n"; + break; + case 27: + cout << "cmd go to stack\n"; + break; + case 32: + cout << "cmd play foreground movie\n"; + break; + case 33: + cout << "cmd play background movie\n"; + break; + case 39: + cout << "cmd activate plst\n"; + break; + case 40: + cout << "cmd activate slst\n"; + break; + case 43: + cout << "cmd activate blst\n"; + break; + case 44: + cout << "cmd activate flst\n"; + break; + case 45: + cout << "cmd do zip mode\n"; + break; + case 46: + cout << "cmd activate mlst\n"; + break; + default: + cout << "unknown cmd " << cmd[0] << endl; + } + +} + + Script::Script (File *fileIn, int start) { cmdList = fileIn->readShortArray (fileIn->getSize () - start, start); @@ -56,5 +176,13 @@ Script::Script (File *fileIn, int start) { } } +void Script::runHandler (Handler::Event event) { + vector::iterator iter; + + for (iter = handler->begin(); iter != handler->end(); iter++) + if ((*iter)->getEventType () == event) + (*iter)->run (); + +} diff --git a/src/Script.h b/src/Script.h index 0ef4453..ef805f4 100644 --- a/src/Script.h +++ b/src/Script.h @@ -35,15 +35,23 @@ private: int findSegmentSize (int offset); + void runSegment (int addr); + public: Handler (uint16_t *cmdListIn); - void run (); + void run () { + runSegment (1); + } - uint16_t getLength () { + uint16_t getLength () { // number of shorts return cmdLength->find(1)->second + 1; } + Event getEventType () { + return eventType; + } + }; @@ -56,10 +64,8 @@ public: Script (File *fileIn, int start); - Handler* getHandler (int i) { - return handler->at(i); - } - + void runHandler (Handler::Event event); + int getSize (); }; diff --git a/src/Tbmp.cpp b/src/Tbmp.cpp index 165290b..90bb403 100644 --- a/src/Tbmp.cpp +++ b/src/Tbmp.cpp @@ -48,17 +48,17 @@ void Tbmp::decompress () { switch (data[d] >> 6) { case 0: d++; - for (k=(data[d-1]*2); k>0; k--) + for (k=data[d-1]; k>0; k--) { image[i++] = data[d++]; + image[i++] = data[d++]; + } break; case 1: - pixel[0] = image[i-2]; - pixel[1] = image[i-1]; d++; for (k=(data[d-1]) & 0x3f; k>0; k--) { - image[i++] = pixel[0]; - image[i++] = pixel[1]; + image[i] = image[i-2]; i++; + image[i] = image[i-2]; i++; } break; diff --git a/src/Variable.cpp b/src/Variable.cpp new file mode 100644 index 0000000..3d520af --- /dev/null +++ b/src/Variable.cpp @@ -0,0 +1,12 @@ + +#include "Variable.h" + +Variable::Variable () { + + data = new map (); + nameRes = (Name *) NULL; +} + + + + diff --git a/src/Variable.h b/src/Variable.h new file mode 100644 index 0000000..a5c49da --- /dev/null +++ b/src/Variable.h @@ -0,0 +1,54 @@ + +#ifndef _VARIABLE_H_ +#define _VARIABLE_H_ + +#include +#include + +#include "Common.h" +#include "Name.h" + +using namespace std; + +class Variable { + + map *data; + Name *nameRes; + +public: + + Variable (); + + void setStack (Stack *stack) { + nameRes = new Name (stack, 4); + } + + uint16_t get (int name) { + if (nameRes != NULL) + return get (nameRes->getString (name)); + } + + uint16_t get (string name) { + return (*data)[name]; + } + + void set (int name, uint16_t val) { + if (nameRes != NULL) + set (nameRes->getString (name), val); + } + + void set (string name, uint16_t val) { + (*data)[name] = val; + } + + void increment (int name, uint16_t value) { + if (nameRes != NULL) + (*data)[nameRes->getString (name)] += value; + } + + +}; + + +#endif + -- 2.11.4.GIT