1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-04 18:29:41 +01:00
VVVVVV/desktop_version/src/Script.h

79 lines
1.3 KiB
C
Raw Normal View History

2020-01-01 21:29:24 +01:00
#ifndef SCRIPT_H
#define SCRIPT_H
#include <string>
#include <vector>
#include <SDL.h>
#define filllines(lines) commands.insert(commands.end(), lines, lines + SDL_arraysize(lines))
2020-01-01 21:29:24 +01:00
struct Script
{
std::string name;
std::vector<std::string> contents;
};
#define NUM_SCRIPT_ARGS 40
2020-01-01 21:29:24 +01:00
class scriptclass
{
public:
scriptclass(void);
2020-01-01 21:29:24 +01:00
void load(const std::string& name);
void loadother(const char* t);
void loadcustom(const std::string& t);
2020-01-01 21:29:24 +01:00
void inline add(const std::string& t)
2020-01-01 21:29:24 +01:00
{
Make `commands`, `sb`, and `hooklist` not use separate length-trackers This is a refactor that turns the script-related arrays `ed.sb`, and `ed.hooklist` into C++ vectors (`script.commands` was already a vector, it was just misused). The code handling these vectors now looks more like idiomatic C++ than sloppily-pasted pseudo-ActionScript. This removes the variables `script.scriptlength`, `ed.sblength`, and `ed.numhooks`, too. This reduces the amount of code needed to e.g. simply remove something from any of these vectors. Previously the code had to manually shift the rest of the elements down one-by-one, and doing it manually is definitely error-prone and tedious. But now we can just use fancy functions like `std::vector::erase()` and `std::remove()` to do it all in one line! Don't worry, I checked and `std::remove()` is in the C++ standard since at least 1998. This patch makes it so the `commands` vector gets cleared when `scriptclass::load()` is ran. Previously, the `commands` vector never actually properly got cleared, so there could potentially be glitches that rely on the game indexing past the bounds set by `scriptlength` but still in-bounds in the eyes of C++, and people could potentially rely on such an exploit... However, I checked, and I'm pretty sure that no such glitch previously existed at all, because the only times the vector gets indexed are when `scriptlength` is either being incremented after starting from 0 (`add()`) or when it's underneath a `position < scriptlength` conditional. Furthermore, I'm unaware of anyone who has actually found or used such an exploit, and I've been in the custom level community for 6 years. So I think it's fine.
2020-02-20 18:43:52 +01:00
commands.push_back(t);
2020-01-01 21:29:24 +01:00
}
void clearcustom(void);
2020-01-01 21:29:24 +01:00
void tokenize(const std::string& t);
2020-01-01 21:29:24 +01:00
void run(void);
2020-01-01 21:29:24 +01:00
void resetgametomenu(void);
2020-01-01 21:29:24 +01:00
void startgamemode(int t);
2020-01-01 21:29:24 +01:00
void teleport(void);
2020-01-01 21:29:24 +01:00
void hardreset(void);
2020-01-01 21:29:24 +01:00
//Script contents
std::vector<std::string> commands;
std::string words[NUM_SCRIPT_ARGS];
2020-01-01 21:29:24 +01:00
std::vector<std::string> txt;
std::string scriptname;
Make `commands`, `sb`, and `hooklist` not use separate length-trackers This is a refactor that turns the script-related arrays `ed.sb`, and `ed.hooklist` into C++ vectors (`script.commands` was already a vector, it was just misused). The code handling these vectors now looks more like idiomatic C++ than sloppily-pasted pseudo-ActionScript. This removes the variables `script.scriptlength`, `ed.sblength`, and `ed.numhooks`, too. This reduces the amount of code needed to e.g. simply remove something from any of these vectors. Previously the code had to manually shift the rest of the elements down one-by-one, and doing it manually is definitely error-prone and tedious. But now we can just use fancy functions like `std::vector::erase()` and `std::remove()` to do it all in one line! Don't worry, I checked and `std::remove()` is in the C++ standard since at least 1998. This patch makes it so the `commands` vector gets cleared when `scriptclass::load()` is ran. Previously, the `commands` vector never actually properly got cleared, so there could potentially be glitches that rely on the game indexing past the bounds set by `scriptlength` but still in-bounds in the eyes of C++, and people could potentially rely on such an exploit... However, I checked, and I'm pretty sure that no such glitch previously existed at all, because the only times the vector gets indexed are when `scriptlength` is either being incremented after starting from 0 (`add()`) or when it's underneath a `position < scriptlength` conditional. Furthermore, I'm unaware of anyone who has actually found or used such an exploit, and I've been in the custom level community for 6 years. So I think it's fine.
2020-02-20 18:43:52 +01:00
int position;
2020-01-01 21:29:24 +01:00
int looppoint, loopcount;
int scriptdelay;
bool running;
2020-01-01 21:29:24 +01:00
//Textbox stuff
int textx;
int texty;
int r,g,b;
bool textflipme;
2020-01-01 21:29:24 +01:00
//Misc
int i, j, k;
//Custom level stuff
std::vector<Script> customscripts;
2020-01-01 21:29:24 +01:00
};
#ifndef SCRIPT_DEFINITION
extern scriptclass script;
#endif
2020-01-01 21:29:24 +01:00
#endif /* SCRIPT_H */