Skip to content

Commit

Permalink
Move all usage of dword_587000_155144
Browse files Browse the repository at this point in the history
  • Loading branch information
blmarket committed Aug 1, 2024
1 parent ff4c0e6 commit c6a7b8a
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 114 deletions.
23 changes: 0 additions & 23 deletions src/audio_ail.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,29 +263,6 @@ func sub_4311F0() int {
return bool2int(v0 != nil && legacy.Sub_487790(v0, 16) == 16)
}

func sub_486F30() int {
nox_common_list_clear_425760(legacy.Get_dword_587000_155144())
nox_common_list_clear_425760(unsafe.Add(legacy.Get_dword_587000_155144(), 12))
*(*uint32)(unsafe.Add(legacy.Get_dword_587000_155144(), 24)) = 0
*memmap.PtrPtr(0x5D4594, 1193340) = unsafe.Add(legacy.Get_dword_587000_155144(), 32)
(*timer.TimerGroup)(unsafe.Add(legacy.Get_dword_587000_155144(), 32)).Init()
dword_5d4594_1193336 = 1
return 0
}

func sub_486EF0() {
if dword_5d4594_1193336 != 0 {
if *(*uint32)(unsafe.Add(legacy.Get_dword_587000_155144(), 24)) == 0 {
v1 := *(*unsafe.Pointer)(unsafe.Add(legacy.Get_dword_587000_155144(), 12))
for it := unsafe.Add(legacy.Get_dword_587000_155144(), 12); v1 != it; v1 = *(*unsafe.Pointer)(v1) {
if (*(*int32)(unsafe.Add(v1, 4*3)) & 2) == 0 {
ccall.CallVoidPtr(*(*unsafe.Pointer)(unsafe.Add(v1, 4*54)), v1)
}
}
}
}
}

var _ = [1]struct{}{}[288-unsafe.Sizeof(audioStructXxx{})]

type audioStructXxx struct {
Expand Down
83 changes: 0 additions & 83 deletions src/legacy/GAME2_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ extern uint32_t dword_5d4594_3798804;
extern uint32_t dword_5d4594_1098576;
extern uint32_t dword_5d4594_3798820;
extern uint32_t dword_5d4594_3798824;
extern void* dword_587000_155144;
extern uint32_t dword_5d4594_3798840;
extern void* dword_5d4594_1123524;
extern uint32_t dword_5d4594_1193380;
Expand Down Expand Up @@ -4433,9 +4432,6 @@ void sub_487030(void* lpMem) {
free(lpMem);
}

//----- (00487050) --------------------------------------------------------
void sub_487050(uint32_t* a1) { nox_common_list_append_4258E0(*(int*)&dword_587000_155144, a1); }

//----- (00487070) --------------------------------------------------------
void sub_487070(void* lpMem) {
sub_487090((uint32_t**)lpMem);
Expand All @@ -4462,15 +4458,6 @@ void sub_4870A0() {
}
}

//----- (004870E0) --------------------------------------------------------
int* sub_4870E0(int* a1) {
int* result; // eax

result = nox_common_list_getFirstSafe_425890(*(int**)&dword_587000_155144);
*a1 = (int)result;
return result;
}

//----- (00487100) --------------------------------------------------------
int* sub_487100(int** a1) {
if (*a1) {
Expand Down Expand Up @@ -4567,20 +4554,6 @@ void sub_4872C0(void* lpMem) {
free(lpMem);
}

//----- (00487310) --------------------------------------------------------
int sub_487310(uint32_t* a1) {
int result; // eax

++*(uint32_t*)((uint32_t)dword_587000_155144 + 24);
nox_common_list_append_4258E0((uint32_t)dword_587000_155144 + 12, a1);
result = *(uint32_t*)((uint32_t)dword_587000_155144 + 24) - 1;
*(uint32_t*)((uint32_t)dword_587000_155144 + 24) = result;
if (result < 0) {
*(uint32_t*)((uint32_t)dword_587000_155144 + 24) = 0;
}
return result;
}

//----- (00487360) --------------------------------------------------------
int* sub_487360(int a1, int** a2, int* a3) {
int* result; // eax
Expand Down Expand Up @@ -4694,68 +4667,12 @@ int sub_487590(int a1, const void* a2) {
return result;
}

//----- (004875B0) --------------------------------------------------------
int* sub_4875B0(int* a1) {
int* result; // eax

result = nox_common_list_getFirstSafe_425890((int*)((uint32_t)dword_587000_155144 + 12));
*a1 = (int)result;
return result;
}

//----- (004875D0) --------------------------------------------------------
int* sub_4875D0(int** a1) {
if (*a1) {
*a1 = nox_common_list_getNextSafe_4258A0(*a1);
}
return *a1;
}

//----- (004875F0) --------------------------------------------------------
int sub_4875F0() {
int* v0; // edi
int* v1; // esi
int result; // eax
int* v3; // [esp+4h] [ebp-4h]

++*(uint32_t*)((uint32_t)dword_587000_155144 + 24);
v0 = sub_4875B0((int*)&v3);
if (v0) {
do {
v1 = sub_4875D0(&v3);
sub_487680(v0);
v0 = v1;
} while (v1);
}
result = *(uint32_t*)((uint32_t)dword_587000_155144 + 24) - 1;
*(uint32_t*)((uint32_t)dword_587000_155144 + 24) = result;
if (result < 0) {
*(uint32_t*)((uint32_t)dword_587000_155144 + 24) = 0;
}
return result;
}

//----- (00487680) --------------------------------------------------------
void sub_487680(void* lpMem) {
sub_4876A0((uint32_t**)lpMem);
sub_4872C0(lpMem);
}

//----- (004876A0) --------------------------------------------------------
void* sub_4876A0(uint32_t** a1) {
void* result; // eax

++*(uint32_t*)((uint32_t)dword_587000_155144 + 24);
nox_common_list_remove_425920(a1);
result = (void*)(*(uint32_t*)((uint32_t)dword_587000_155144 + 24) - 1);
*(uint32_t*)((uint32_t)dword_587000_155144 + 24) = result;
if ((int)result < 0) {
result = *(void**)&dword_587000_155144;
*(uint32_t*)((uint32_t)dword_587000_155144 + 24) = 0;
}
return result;
}

//----- (00487750) --------------------------------------------------------
uint32_t* sub_487750(int a1) {
uint32_t* v1; // eax
Expand Down
3 changes: 1 addition & 2 deletions src/legacy/GAME2_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,8 @@ int sub_4873C0(int a3);
int sub_487590(int a1, const void* a2);
int* sub_4875B0(int* a1);
int* sub_4875D0(int** a1);
int sub_4875F0();
void sub_487680(void* lpMem);
void* sub_4876A0(uint32_t** a1);
void sub_4876A0(uint32_t** a1);
uint32_t* sub_487750(int a1);
int sub_487790(int a1, int a2);
int* sub_4877D0(int a1, int* a2);
Expand Down
25 changes: 24 additions & 1 deletion src/legacy/audio_ail.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ extern void* dword_587000_122852;
extern void* dword_587000_81128;
extern void* dword_587000_93164;
extern void* dword_5d4594_805984;
extern void* dword_587000_155144;
*/
import "C"
import (
Expand All @@ -55,6 +54,10 @@ var (
Sub_43F060 func(a1p unsafe.Pointer) int
Sub_43EC30 func(a1 unsafe.Pointer) int
Sub_43ECB0 func(a1 unsafe.Pointer) int
Sub_487050 func(a1 unsafe.Pointer)
Sub_4870E0 func(a1 unsafe.Pointer) unsafe.Pointer
Sub_487310 func(a1 unsafe.Pointer) int32
Sub_4876A0 func(a1 unsafe.Pointer)
)

type _WIN32_FIND_DATAA = C.struct__WIN32_FIND_DATAA
Expand Down Expand Up @@ -382,3 +385,23 @@ func sub_44D8F0() { Dialogs.Sub_44D8F0() }
func sub_44D5C0(a1 int, a2 int) {
Dialogs.Sub_44D5C0(ail.Stream(a1), a2)
}

//export sub_487050
func sub_487050(a1 *uint32) {
Sub_487050(unsafe.Pointer(a1))
}

//export sub_4870E0
func sub_4870E0(a1 *int32) *int32 {
return (*int32)(Sub_4870E0(unsafe.Pointer(a1)))
}

//export sub_487310
func sub_487310(a1 *uint32) int32 {
return Sub_487310(unsafe.Pointer(a1))
}

//export sub_4876A0
func sub_4876A0(a1 **uint32) {
Sub_4876A0(unsafe.Pointer(a1))
}
9 changes: 5 additions & 4 deletions src/legacy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern unsigned int dword_587000_93156;
extern nox_gui_animation* nox_wnd_xxx_1309740;
*/
import "C"
import "unsafe"

var (
Nox_exit func(exitCode int)
Expand Down Expand Up @@ -111,10 +112,6 @@ func Sub_431270() {
C.sub_431270()
}

func Sub_4875F0() {
C.sub_4875F0()
}

func Sub_4870A0() {
C.sub_4870A0()
}
Expand All @@ -130,3 +127,7 @@ func Nox_xxx_servSetPlrLimit_409F80(v int) {
func Nox_xxx_guiChatShowHide_445730(v bool) {
C.nox_xxx_guiChatShowHide_445730(C.int(bool2int(v)))
}

func Sub_487680(a1 unsafe.Pointer) {
C.sub_487680(a1)
}
6 changes: 6 additions & 0 deletions src/legacy_exports.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package opennox

import (
"unsafe"

"github.com/noxworld-dev/opennox-lib/types"

"github.com/noxworld-dev/opennox/v1/client"
Expand Down Expand Up @@ -151,6 +153,10 @@ func init() {
legacy.Sub_43F060 = sub_43F060
legacy.Sub_43EC30 = sub_43EC30
legacy.Sub_43ECB0 = sub_43ECB0
legacy.Sub_487050 = func(a1 unsafe.Pointer) { sub_487050((*Struct88)(a1)) }
legacy.Sub_4870E0 = func(a1 unsafe.Pointer) unsafe.Pointer { return unsafe.Pointer(sub_4870E0((**Struct88)(a1))) }
legacy.Sub_487310 = func(a1 unsafe.Pointer) int32 { return sub_487310((*Struct264)(a1)) }
legacy.Sub_4876A0 = func(a1 unsafe.Pointer) { sub_4876A0((*Struct264)(a1)) }
legacy.Nox_xxx_updateSprings_5113A0 = nox_xxx_updateSprings_5113A0
legacy.Nox_xxx_unitIsUnitTT_4E7C80 = nox_xxx_unitIsUnitTT_4E7C80
legacy.Nox_xxx_updatePlayer_4F8100 = nox_xxx_updatePlayer_4F8100
Expand Down
2 changes: 1 addition & 1 deletion src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func sub_4311B0() {
legacy.Set_dword_587000_81128(nil)
legacy.Sub_431270()
if dword_5d4594_1193336 != 0 {
legacy.Sub_4875F0()
sub_4875F0()
legacy.Sub_4870A0()
dword_5d4594_1193336 = 0
}
Expand Down
131 changes: 131 additions & 0 deletions src/struct_155144.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package opennox

import (
"unsafe"

"github.com/noxworld-dev/opennox/v1/common/memmap"
"github.com/noxworld-dev/opennox/v1/legacy"
"github.com/noxworld-dev/opennox/v1/legacy/common/ccall"
"github.com/noxworld-dev/opennox/v1/legacy/timer"
)

type Struct88 struct {
field_0 listItem
field_12 [19]uint32
}

func (s *Struct88) getList() *listItem {
return &s.field_0
}

type Struct264 struct {
field_0 listItem
field_12 [63]uint32
}

func (s *Struct264) getList() *listItem {
return &s.field_0
}

type StructAt155144 struct {
field_0 listHead[Struct88, *Struct88]
field_12 listHead[Struct264, *Struct264]
field_24 int32
field_28 uint32 // unused
field_32 timer.TimerGroup
}

func inst() *StructAt155144 {
return (*StructAt155144)(legacy.Get_dword_587000_155144())
}

func sub_486F30() int {
inst().field_0.Clear()
inst().field_12.Clear()
inst().field_24 = 0
*memmap.PtrT[*timer.TimerGroup](0x5D4594, 1193340) = &inst().field_32
inst().field_32.Init()
dword_5d4594_1193336 = 1
return 0
}

func sub_486EF0() {
if dword_5d4594_1193336 != 0 {
if inst().field_24 == 0 {
listHead := &inst().field_12
for v1 := listHead.next; v1 != &listHead.listItem; v1 = v1.next {
if (*(*int32)(unsafe.Add(unsafe.Pointer(v1), 4*3)) & 2) == 0 {
ccall.CallVoidPtr(*(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(v1), 4*54)), unsafe.Pointer(v1))
}
}
}
}
}

func sub_487050(a1 *Struct88) {
inst().field_0.Append(a1)
}

func sub_4870E0(a1 **Struct88) *Struct88 {
result := inst().field_0.First()
*a1 = result
return result
}

func sub_487310(a1 *Struct264) int32 {
inst().field_24 += 1
inst().field_12.Append(a1)
result := inst().field_24 - 1
inst().field_24 = result
if result < 0 {
inst().field_24 = 0
}
return result
}

func sub_4875B0(a1 **Struct264) *Struct264 {
result := inst().field_12.First()
*a1 = result
return result
}

// ----- (004875D0) --------------------------------------------------------
func sub_4875D0(a1 **Struct264) *Struct264 {
if *a1 != nil {
// FIXME: should be no cast
*a1 = (*Struct264)(unsafe.Pointer((*a1).getList().Next()))
}
return *a1
}

func sub_4875F0() int32 {
inst().field_24 += 1
var v3 *Struct264
v0 := sub_4875B0(&v3)
if v0 != nil {
for {
v1 := sub_4875D0(&v3)
legacy.Sub_487680(unsafe.Pointer(v0))
v0 = v1
if v1 == nil {
break
}
}
}
result := inst().field_24 - 1
inst().field_24 = result
if result < 0 {
inst().field_24 = 0
}
return result
}

func sub_4876A0(a1 *Struct264) {
inst().field_24 += 1
a1.getList().Remove()
result := inst().field_24 - 1
inst().field_24 = result
if result < 0 {
inst().field_24 = 0
}
}

0 comments on commit c6a7b8a

Please sign in to comment.