Add target_new

This commit is contained in:
Alexander Batalov 2023-09-02 17:54:17 +03:00
parent fe47d88035
commit 8d2d5df65f
2 changed files with 47 additions and 10 deletions

View File

@ -22,7 +22,7 @@ typedef struct TargetNode {
typedef struct TargetList {
TargetNode* tail;
int count;
int field_8;
int next_tid;
} TargetList;
// 0x53F354
@ -245,7 +245,7 @@ int target_find_free_subnode(TargetSubNode** subnode_ptr)
*subnode_ptr = &(node->subnode);
node->subnode.field_0 = -1;
node->subnode.pid = -1;
node->subnode.next = NULL;
node->next = targetlist.tail;
@ -255,6 +255,42 @@ int target_find_free_subnode(TargetSubNode** subnode_ptr)
return 0;
}
// 0x49BA10
int target_new(int pid, int* tid_ptr)
{
TargetSubNode* subnode;
TargetSubNode* new_subnode;
if (target_ptr(pid, &subnode) == -1) {
if (target_find_free_subnode(&subnode) == -1) {
return -1;
}
}
new_subnode = (TargetSubNode*)internal_malloc(sizeof(TargetSubNode));
if (new_subnode == NULL) {
return -1;
}
new_subnode->next = NULL;
while (subnode->next != NULL) {
subnode = subnode->next;
}
subnode->next = new_subnode;
new_subnode->pid = pid;
new_subnode->tid = targetlist.next_tid;
*tid_ptr = targetlist.next_tid;
targetlist.count++;
targetlist.next_tid++;
return 0;
}
// 0x49BBD4
int target_remove(int pid)
{
@ -264,7 +300,7 @@ int target_remove(int pid)
node = targetlist.tail;
while (node != NULL) {
if (node->subnode.field_0 == pid) {
if (node->subnode.pid == pid) {
break;
}
node = node->next;
@ -300,7 +336,7 @@ int target_remove_tid(int pid, int tid)
node = targetlist.tail;
while (node != NULL) {
if (node->subnode.field_0 == pid) {
if (node->subnode.pid == pid) {
break;
}
node = node->next;
@ -310,7 +346,7 @@ int target_remove_tid(int pid, int tid)
return -1;
}
if (node->subnode.field_4 == tid) {
if (node->subnode.tid == tid) {
subnode_next = node->subnode.next;
if (subnode_next != NULL) {
memcpy(&(node->subnode), subnode_next, sizeof(TargetSubNode));
@ -324,7 +360,7 @@ int target_remove_tid(int pid, int tid)
subnode = &(node->subnode);
while (subnode != NULL) {
subnode_next = subnode->next;
if (subnode_next->field_4 == tid) {
if (subnode_next->tid == tid) {
subnode->next = subnode_next->next;
internal_free(subnode_next);
return 0;
@ -370,7 +406,7 @@ int target_ptr(int pid, TargetSubNode** subnode_ptr)
{
TargetNode* node = targetlist.tail;
while (node != NULL) {
if (node->subnode.field_0 == pid) {
if (node->subnode.pid == pid) {
*subnode_ptr = &(node->subnode);
return 0;
}
@ -388,7 +424,7 @@ int target_tid_ptr(int pid, int tid, TargetSubNode** subnode_ptr)
}
while (subnode != NULL) {
if (subnode->field_4 == tid) {
if (subnode->tid == tid) {
*subnode_ptr = subnode;
return 0;
}

View File

@ -4,8 +4,8 @@
namespace fallout {
typedef struct TargetSubNode {
int field_0;
int field_4;
int pid;
int tid;
int field_8;
int field_C;
int field_10;
@ -56,6 +56,7 @@ int target_header_load();
int target_save(int pid);
int target_load(int pid, TargetSubNode** subnode_ptr);
int target_find_free_subnode(TargetSubNode** subnode_ptr);
int target_new(int pid, int* tid_ptr);
int target_remove(int pid);
int target_remove_tid(int pid, int tid);
int target_remove_all();