Skip to content

Commit

Permalink
Implemented @excluderandom command
Browse files Browse the repository at this point in the history
  • Loading branch information
adm244 committed Jul 4, 2018
1 parent e343304 commit fa67d06
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 35 deletions.
48 changes: 18 additions & 30 deletions code/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ OTHER DEALINGS IN THE SOFTWARE.
- Check if player is in dialogue
- Check if menu is opened
- Check if vats is active
- @excluderandom command to exclude batch from random
TODO:
- Add comments support to batch files
- Rewrite hooking mechanism (detours)
Expand Down Expand Up @@ -193,14 +194,14 @@ internal void ProcessQueue(Queue *queue, bool checkExecState)
}

if( checkExecState ) {
uint8 executionState = GetBatchExecState(batch->filename);
//uint8 executionState = GetBatchExecState(batch->filename);

bool executionStateValid = ((executionState == EXEC_EXTERIOR_ONLY) && !IsInterior)
|| ((executionState == EXEC_INTERIOR_ONLY) && IsInterior)
|| (executionState == EXEC_DEFAULT);
bool executionStateValid = ((batch->executionState == EXEC_EXTERIOR_ONLY) && !IsInterior)
|| ((batch->executionState == EXEC_INTERIOR_ONLY) && IsInterior)
|| (batch->executionState == EXEC_DEFAULT);

if( !executionStateValid ) {
if( executionState == EXEC_EXTERIOR_ONLY ) {
if( batch->executionState == EXEC_EXTERIOR_ONLY ) {
QueuePut(&ExteriorPendingQueue, dataPointer);
} else {
QueuePut(&InteriorPendingQueue, dataPointer);
Expand Down Expand Up @@ -256,35 +257,22 @@ internal DWORD WINAPI QueueHandler(LPVOID data)
}

if( IsActivated(&CommandRandom) ) {
int index = RandomInt(0, batches_count - 1);
QueuePut(&BatchQueue, (pointer)&batches[index]);
DisplayRandomSuccessMessage(batches[index].description);

/*if (IsMenuOpen("VATSMenu")) {
DisplayMessage("Menu IS opened.");
} else {
DisplayMessage("Menu is NOT opened.");
}*/

/*if (IsInMenuMode()) {
DisplayMessage("IS menu mode.");
/*BatchData *batch = GetRandomBatch(&randomBatchGroup);
if( batch ) {
QueuePut(&BatchQueue, (pointer)batch);
DisplayRandomSuccessMessage(batch->description);
} else {
DisplayMessage("Is NOT menu mode.");
DisplayRandomFailureMessage();
}*/

/*if( IsInDialogueWithPlayer((TESActor *)TES_GetPlayer()) ) {
DisplayMessage("Player IS in dialogue.");
} else {
DisplayMessage("Player is NOT in dialogue.");
}*/
int index = -1;
//NOTE(adm244): temporary solution...
do {
index = RandomInt(0, batches_count - 1);
} while( batches[index].excludeRandom );

/*TESObjectReference *playerRef = (TESObjectReference *)TES_GetPlayer();
TESCell *playerCell = playerRef->parentCell;
if( IsCellWithinBorderRegion(playerCell) ) {
DisplayMessage("Cell is WITHIN border region.");
} else {
DisplayMessage("Cell is OUTSIDE border region.");
}*/
QueuePut(&BatchQueue, (pointer)&batches[index]);
DisplayRandomSuccessMessage(batches[index].description);
}
}
}
Expand Down
75 changes: 70 additions & 5 deletions code/silverlib/batch_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ OTHER DEALINGS IN THE SOFTWARE.
#define BATCH_EXTERIOR "@exterior"
#define BATCH_INTERIOR_ONLY "@interioronly"
#define BATCH_EXTERIOR_ONLY "@exterioronly"
#define BATCH_RANDOM_EXCLUDE "@randomexclude"

//TODO(adm244): remove this
//TODO(adm244): move outside
Expand All @@ -46,30 +47,51 @@ OTHER DEALINGS IN THE SOFTWARE.
#define EXEC_INTERIOR_ONLY 3
#define EXEC_EXTERIOR_ONLY 4

struct BatchData{
struct BatchData {
char filename[MAX_FILENAME];
char description[MAX_DESCRIPTION];

uint64 offset;
int timerIndex;

int key;
uint executionState;
bool excludeRandom;

bool enabled;
};

struct CustomCommand{
struct CustomCommand {
int key;
bool enabled;
};

/*struct BatchGroup {
uint length;
uint batches[MAX_BATCHES];
};*/

internal BatchData batches[MAX_BATCHES];
//internal BatchGroup randomBatchGroup;
internal CustomCommand CommandToggle;
internal CustomCommand CommandRandom;

internal bool keys_active = true;
internal bool not_initialized = true;
internal int batches_count = 0;

/*internal BatchData * GetRandomBatch(BatchGroup *group)
{
BatchData *result = 0;
if( group && group->length > 0 ) {
int index = RandomInt(0, group->length - 1);
result = &(group->batches[index]);
}
return result;
}*/

internal void Teleport()
{
TESWorldSpace *worldspace = GetPlayerCurrentWorldSpace();
Expand Down Expand Up @@ -129,6 +151,44 @@ internal bool IsActivated(CustomCommand *cmd)
return(IsActivated(cmd->key, &cmd->enabled));
}

internal void ReadBatchFile(BatchData *batch)
{
FILE *src = NULL;
fopen_s(&src, batch->filename, "r");

if( src ){
char line[4096];

fgets(line, sizeof(line), src);

uint32 lineLen = strlen(line);
if(line[lineLen - 1] == '\n'){
line[lineLen - 1] = 0;
}
strcpy(batch->description, line);

while( fgets(line, sizeof(line), src) ){
uint32 lineLen = strlen(line);

if(line[lineLen - 1] == '\n'){
line[lineLen - 1] = 0;
}

if( strcmp(line, BATCH_EXTERIOR_ONLY) == 0 ) {
batch->executionState = EXEC_EXTERIOR_ONLY;
} else if( strcmp(line, BATCH_INTERIOR_ONLY) == 0 ) {
batch->executionState = EXEC_INTERIOR_ONLY;
} else if (strcmp(line, BATCH_RANDOM_EXCLUDE) == 0 ) {
batch->excludeRandom = true;
}
}

fclose(src);
} else {
//NOTE(adm244): couldn't read a file
}
}

//NOTE(adm244): loads a list of batch files and keys that activate them
// filename and associated keycode stored in a BatchData structure pointed to by 'batches'
//
Expand All @@ -154,8 +214,11 @@ internal bool InitBatchFiles(HMODULE module, BatchData *batches, int *num)
batches[index].timerIndex = -1;
batches[index].offset = 0;
batches[index].key = (int)strtol(p, &endptr, 0);
batches[index].excludeRandom = false;
batches[index].enabled = true;

ReadBatchFile(&batches[index]);

str = strchr(p, '\0');
str++;

Expand All @@ -169,7 +232,7 @@ internal bool InitBatchFiles(HMODULE module, BatchData *batches, int *num)
return(index > 0);
}

internal void ReadBatchDescriptions(BatchData *batches)
/*internal void ReadBatchDescriptions(BatchData *batches)
{
FILE *file = NULL;
char line[MAX_DESCRIPTION];
Expand Down Expand Up @@ -226,7 +289,7 @@ internal uint8 GetBatchExecState(char *filename)
}
return result;
}
}*/

enum ExecuteBatch_ResultCodes {
ExecuteBatch_Fail = -1,
Expand Down Expand Up @@ -289,6 +352,8 @@ internal int ExecuteBatch(BatchData *batch, uint64 offset)
//NOTE(adm244): should be empty
} else if( strcmp(line, BATCH_EXTERIOR_ONLY) == 0 ) {
//NOTE(adm244): should be empty
} else if (strcmp(line, BATCH_RANDOM_EXCLUDE) == 0 ) {
//NOTE(adm244): should be empty
} else {
if( (IsInterior && (executionState == EXEC_INTERIOR))
|| (!IsInterior && (executionState == EXEC_EXTERIOR))
Expand All @@ -314,7 +379,7 @@ internal int InitilizeBatches(HMODULE module)
{
keys_active = true;
InitBatchFiles(module, batches, &batches_count);
ReadBatchDescriptions(batches);
//ReadBatchDescriptions(batches);

//TODO(adm244): rewrite IniRead* functions so they accept full path to config file folder
CommandToggle.key = IniReadInt(module, CONFIG_FILE, CONFIG_KEYS_SECTION, "iKeyToggle", VK_HOME);
Expand Down
1 change: 1 addition & 0 deletions data/f4teleport
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Kidnapping
@randomexclude
@timeout 5
@teleport

0 comments on commit fa67d06

Please sign in to comment.